Skip to main content
Inspiring
October 29, 2015
Answered

Apply overprint only to black objects & texts

  • October 29, 2015
  • 1 reply
  • 775 views

Hi,

I am trying to write a script that apply Overprinting attribute to all objects & texts on all layers only to K=100.

I start from unlocking layers...

var doc = app.activeDocument;

for (i=0; i<doc.layers.length; i++)

            doc.layers.locked = false;

By the way, is it possible to 'read' locked/unlocked state of the all layers by Javascript, perform some operations, and then lock back layers and leave unlocked ones as they were before performing the script?

Pete

This topic has been closed for replies.
Correct answer Vinicius Baptista

Hi Pete,

Well, answering the question of this post, use this code:

var totalItens = app.activeDocument.pageItems.length;

var items = app.activeDocument.pageItems;

for (i = 0; i < totalItens; i++){ 

 

 

    if(items.typename == 'PathItem'){ 

       

        if (items.fillColor.cyan == 0 && items.fillColor.magenta == 0 && items.fillColor.yellow == 0 && items.fillColor.black == 100){ 

            if (items.fillOverprint == false){ 

            items.fillOverprint = true; 

            }; 

        }; 

        if (items.strokeColor.cyan == 0 && items.strokeColor.magenta == 0 && items.strokeColor.yellow == 0 && items.strokeColor.black == 100){ 

            if (items.strokeOverprint == false){ 

            items.strokeOverprint = true; 

            }; 

        }; 

     

    }; 

 

 

    if(items.typename == 'TextFrame'){ 

        for ( var j = 0; j < items.textRanges.length; j++ ) {   

 

            if (items.textRanges.fillColor.cyan == 0 && items.textRanges.fillColor.magenta == 0 && items.textRanges.fillColor.yellow == 0 && items.textRanges.fillColor.black == 100){ 

                if (items.textRanges.characterAttributes.overprintFill == false){ 

                    items.textRanges.characterAttributes.overprintFill = true; 

                }; 

            }; 

            if (items.textRanges.strokeColor.cyan == 0 && items.textRanges.strokeColor.magenta == 0 && items.textRanges.strokeColor.yellow == 0 && items.textRanges.strokeColor.black == 100){ 

                if (items.textRanges.characterAttributes.overprintStroke == false){ 

                    items.textRanges.characterAttributes.overprintStroke = true; 

                }; 

            }; 

 

 

        }; 

         

    }; 

     

}; 

 

And, answering the second question: Yes OfCourse, you can unlock the layers, perform some operations and then lock it back. But is better you say what you trying to do, what the purpose of this?

I hope helped, bests, Vinícius.

1 reply

Vinicius Baptista
Vinicius BaptistaCorrect answer
Inspiring
October 30, 2015

Hi Pete,

Well, answering the question of this post, use this code:

var totalItens = app.activeDocument.pageItems.length;

var items = app.activeDocument.pageItems;

for (i = 0; i < totalItens; i++){ 

 

 

    if(items.typename == 'PathItem'){ 

       

        if (items.fillColor.cyan == 0 && items.fillColor.magenta == 0 && items.fillColor.yellow == 0 && items.fillColor.black == 100){ 

            if (items.fillOverprint == false){ 

            items.fillOverprint = true; 

            }; 

        }; 

        if (items.strokeColor.cyan == 0 && items.strokeColor.magenta == 0 && items.strokeColor.yellow == 0 && items.strokeColor.black == 100){ 

            if (items.strokeOverprint == false){ 

            items.strokeOverprint = true; 

            }; 

        }; 

     

    }; 

 

 

    if(items.typename == 'TextFrame'){ 

        for ( var j = 0; j < items.textRanges.length; j++ ) {   

 

            if (items.textRanges.fillColor.cyan == 0 && items.textRanges.fillColor.magenta == 0 && items.textRanges.fillColor.yellow == 0 && items.textRanges.fillColor.black == 100){ 

                if (items.textRanges.characterAttributes.overprintFill == false){ 

                    items.textRanges.characterAttributes.overprintFill = true; 

                }; 

            }; 

            if (items.textRanges.strokeColor.cyan == 0 && items.textRanges.strokeColor.magenta == 0 && items.textRanges.strokeColor.yellow == 0 && items.textRanges.strokeColor.black == 100){ 

                if (items.textRanges.characterAttributes.overprintStroke == false){ 

                    items.textRanges.characterAttributes.overprintStroke = true; 

                }; 

            }; 

 

 

        }; 

         

    }; 

     

}; 

 

And, answering the second question: Yes OfCourse, you can unlock the layers, perform some operations and then lock it back. But is better you say what you trying to do, what the purpose of this?

I hope helped, bests, Vinícius.

Pete StanAuthor
Inspiring
October 30, 2015

Hi Vinícius,

This works like a charm! Thanks!

Second question:

Because I am unable to lock the layers with variable name in it in different files (see sample screenshot):

It means that every file has different name of the layer Info (there are plenty of combinations but always starts with 'Info')

Mind that I would sometimes have more layers so won't be able to lock always the layer at the very top:

Normally I could perform:

function tryLockLayer(name) {

        try {

            lrs.getByName(name).locked = true;

        } catch(e) {

            return;

        }

    };

    var lrs = doc.layers;

    tryLockLayer("Information");

    tryLockLayer("Info Layer");

    tryLockLayer("Info");

But the problem is that I am not able to 'predict' all the names of that layer in incoming files, there are too many combinations.

I don't think I would be able to use Regex to match the pattern thats starts from info, like \<Inf\w+ hence I do lock the layer manually before running any script

Peter

Vinicius Baptista
Inspiring
October 30, 2015

Hi, glad to have helped...

Well, as the question was answered this topic, I suggest you mark as "answered" to help facilitate research forum here, I'm trying to provide the solution to this second answer, if you prefer you can create a new topic with this question.

And we going ahead...

See ya!!

Best regards, Vinícius.