Skip to main content
ScriptingRules
Known Participant
October 9, 2012
Answered

Scripting Layer Moves

  • October 9, 2012
  • 2 replies
  • 7176 views

I've been trying to find a way to move some layers and sub layers under a master layer.  Does someone have a line on the code to process this type of move?

From

Layer 1

Layer 2

   Sub Layer 1

   Sub Layer 2

Layer 3

To

Master Layer

   Layer 1

   Layer 2

      Sub Layer 1

      Sub Layer 2

   Layer 3

Thanks for your help!!!

This topic has been closed for replies.
Correct answer Muppet Mark

Moving objects is simple enough to do… Where did Master Layer come from… You already add it or does the script do that too?

#target illustrator

main();

function main() {

 

          if ( app.documents.length == 0 ) { return; }

 

          app.userInteractionLevel = UserInteractionLevel.DONTDISPLAYALERTS;

          var doc = app.activeDocument;

 

          var mast = doc.layers.add();

 

          mast.name = 'Master Layer';

          for ( var  i = doc.layers.length-1; i >= 1; i-- ) {

 

                    doc.layers.move( mast, ElementPlacement.PLACEATBEGINNING )

          };

};

2 replies

Babymac08
Known Participant
November 22, 2016

Thank you so much... Now you have me thinking... I'm not overly familiar with scripts... but This type of set-up I'm creating we run into often... Can you let me know if this is something that could be accomplished in one step...

1. Run a script on an individual .tif or a folder of *.tif files

2. Open in Illustrator and place on a layer named "artwork"

3. Create a new layer named "Through Cut" and make a 1pt stroke that is .25" (H & W) less than the input file size (ie: input file is 48.25 x 96.25 rectangle would be 48 x 96 Centered) However I'd love it if the size could be determined from the input.

4. Do the layer flip like you previously assisted with putting Through Cut on Top / Artwork on Bottom

5. Print using a particular print preset (700 w-crops_Bleeds)

6. Flip the layers back to the order of Artwork on top and Through Cut on Bottom.

7. Save .pdf file (with PDF preset) with same name as input file.

8. Close

What I'm not sure of if it can handle the variable of input file being different sizes and creating the rectangle based off that...

Thanks again so much for your feedback... It's greatly appreciated.

Muppet MarkCorrect answer
Inspiring
October 9, 2012

Moving objects is simple enough to do… Where did Master Layer come from… You already add it or does the script do that too?

#target illustrator

main();

function main() {

 

          if ( app.documents.length == 0 ) { return; }

 

          app.userInteractionLevel = UserInteractionLevel.DONTDISPLAYALERTS;

          var doc = app.activeDocument;

 

          var mast = doc.layers.add();

 

          mast.name = 'Master Layer';

          for ( var  i = doc.layers.length-1; i >= 1; i-- ) {

 

                    doc.layers.move( mast, ElementPlacement.PLACEATBEGINNING )

          };

};

ScriptingRules
Known Participant
October 9, 2012

Easier than I thought.  Thank you very much.  Below is my final function.  The Master Layer is generated from the file name.

#target illustrator

packageDesign();

function packageDesign() {       // Create new layer based off of file name and move all layers underneath.

   

                var sourceDoc = app.activeDocument;

                var fileName = sourceDoc.name;

                var newLayer = "";

                var newName = "";

                var dot = fileName.lastIndexOf('.');

                var myLayerCount = sourceDoc.layers.length

                newName = fileName.substring(0, dot);

               

                mast = sourceDoc.layers.add()

                mast.name = newName

 

          if ( app.documents.length == 0 ) { return; }

         

         

            for(var myCounter = 0; myCounter < myLayerCount+1; myCounter++){

               var selectLayer = sourceDoc.layers[myCounter]

                       

                   selectLayer.visible=true

                   selectLayer.locked=false

            }      

            for ( var  i = sourceDoc.layers.length-1; i >= 1; i-- ) {

 

                   sourceDoc.layers.move( mast, ElementPlacement.PLACEATBEGINNING )

          };

};

Brandi Leath
Participating Frequently
November 30, 2015

I am looking to do this exact same thing, except in Photoshop, can you help me with that? Thanks!!! - Brandi