4 Replies Latest reply on Oct 30, 2015 4:50 AM by Vinicius Baptista

    Apply overprint only to black objects & texts

    Pete Stan



      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[i].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?



        • 1. Re: Apply overprint only to black objects & texts
          Vinicius Baptista Level 2

          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[i].typename == 'PathItem'){  
                  if (items[i].fillColor.cyan == 0 && items[i].fillColor.magenta == 0 && items[i].fillColor.yellow == 0 && items[i].fillColor.black == 100){  
                      if (items[i].fillOverprint == false){  
                      items[i].fillOverprint = true;  
                  if (items[i].strokeColor.cyan == 0 && items[i].strokeColor.magenta == 0 && items[i].strokeColor.yellow == 0 && items[i].strokeColor.black == 100){  
                      if (items[i].strokeOverprint == false){  
                      items[i].strokeOverprint = true;  
              if(items[i].typename == 'TextFrame'){  
                  for ( var j = 0; j < items[i].textRanges.length; j++ ) {    
                      if (items[i].textRanges[j].fillColor.cyan == 0 && items[i].textRanges[j].fillColor.magenta == 0 && items[i].textRanges[j].fillColor.yellow == 0 && items[i].textRanges[j].fillColor.black == 100){  
                          if (items[i].textRanges[j].characterAttributes.overprintFill == false){  
                              items[i].textRanges[j].characterAttributes.overprintFill = true;  
                      if (items[i].textRanges[j].strokeColor.cyan == 0 && items[i].textRanges[j].strokeColor.magenta == 0 && items[i].textRanges[j].strokeColor.yellow == 0 && items[i].textRanges[j].strokeColor.black == 100){  
                          if (items[i].textRanges[j].characterAttributes.overprintStroke == false){  
                              items[i].textRanges[j].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 person found this helpful
          • 2. Re: Apply overprint only to black objects & texts
            Pete Stan Level 1

            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:

            Screen Shot 2015-10-30 at 08.54.19.png



            Normally I could perform:

            function tryLockLayer(name) {
                    try {
                        lrs.getByName(name).locked = true;
                    } catch(e) {
                var lrs = doc.layers;
                tryLockLayer("Info Layer");


            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



            • 3. Re: Apply overprint only to black objects & texts
              Vinicius Baptista Level 2

              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.

              • 4. Re: Apply overprint only to black objects & texts
                Vinicius Baptista Level 2

                On time, to your second question:


                This loop will lock all the layers with word 'Inf' in your name, Information, Inf, Info, layerInfo, layer 1 Information, whatever.... Note: It's considered the Uppercase and Lowercase.


                var layersLength = app.activeDocument.layers.length;
                for (i=0; i < layersLength; i++){
                    nameLayer = app.activeDocument.layers[i].name;
                    if (nameLayer.indexOf('Inf') != '-1'){
                        app.activeDocument.layers[i].locked = true;


                Hope it works,