5 Replies Latest reply on May 16, 2013 11:25 AM by big_smile

    Indesign Scripting: Loop through Layers

    big_smile Level 1

      I am trying to make a script that will:


      Loop through all layers of a document.

      Add the unlocked layers to array

      Loop through this array and paste in place on each layer.



      I am not sure how to loop through all layers.


      Here is my script (I have used ??? to represent where the loop through all layers part would go):

      // JavaScript Document

      //Set up an array to hold unlocked layers

      var layercollection = [];


      //Loop through Layers and unlocked layers to the layercollection array

      for (i = 0; ? ? ? i++) {

                app.activeDocument.activeLayer = app.activeDocument.layers.itemByName( ? ? ? );

                if (app.documents[0].layers. ([i]).locked) == false;




      // Loop through layercollection array and paste in place

      for (i = 0; i < layercollection.length; i++) {

                app.activeDocument.activeLayer = app.activeDocument.layers.itemByName(tl[i]);

                app.pasteInPlace(); //Paste




      Can someone help me complete my script.