Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Scripting Layer Moves

Community Beginner ,
Oct 09, 2012 Oct 09, 2012

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!!!

TOPICS
Scripting
7.4K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Mentor , Oct 09, 2012 Oct 09, 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-- ) {

 

                   

...
Translate
Adobe
Mentor ,
Oct 09, 2012 Oct 09, 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 )

          };

};

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Oct 09, 2012 Oct 09, 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 )

          };

};

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Nov 30, 2015 Nov 30, 2015

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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Mentor ,
Dec 01, 2015 Dec 01, 2015
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Dec 01, 2015 Dec 01, 2015

actually got it....in case anyone needs it.

Re: rename background layer to file name and move to top

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Nov 22, 2016 Nov 22, 2016

This might be similiar to what I'm trying to do... Can you help...

I have a batch of files that I'm running an action on and I need it to flip the order of layers temporarily for printing notes and etc...

So my file is set-up as

top Layer = Artwork

Bottom Layer = Through Cut

I need the script to flip these so I can execute a print command, then flip them back to original order

Can you help? - Thanks so much

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Mentor ,
Nov 22, 2016 Nov 22, 2016

function wrapper()

{

     var docRef = app.activeDocument;

     var layers = docRef.layers;

     var artLayer = layers["Artwork"];

     var thruCutLayer = layers["Through Cut"];

    

     function bringThruCutForward()

     {

          thruCutLayer.zOrder(ZOrderMethod.BRINGTOFRONT);

     }

     function sendThruCutBackward()

     {

          thruCutLayer.zOrder(ZOrderMethod.SENDTOBACK);

     }

     function printCommand()

     {

          //code to print file

     }

     bringThruCutForward();

     printCommand();

     sendThruCutBackward();

}

wrapper();

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Apr 26, 2018 Apr 26, 2018

These tips are extremely helpful. I am trying to select all items with a specific color, and move them to a specific layer. I get a number of Die files that have 7 colors that need to be moved to specific layer names. Although this is easy to do manually, scripting it would make life so much better.

I'd like to "select all same stroke color" on layer 15

Move to sublayer "Bleed" which is

The documents will all start with:

Layer 15

Template

     Cut

     Score

     Bleed

All of the art I need to move will start on Layer 15 and I need to select all same stroke then move for all 7 inks.

Can someone help get me started with the correct commands?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Mentor ,
Apr 26, 2018 Apr 26, 2018

Hello Ed,

Welcome to the world of scripting! You've definitely come to the right place for help. There are lots of great coders here who are always eager to answer as many questions as you have.

To help keep this forum clean, organized, and easy to search, it would be helpful for you to create a new post for your question. That way if somebody searches for a similar problem in the future, they won't have to scroll through all of the unrelated responses in this post. Additionally, that will give you the ability to give good feedback to anyone who helps, including marking your question as answered.

I'll look for your new post. 😃

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Apr 26, 2018 Apr 26, 2018
LATEST

Thank you I am trying to get that done now.

Ed Schrempf

847-489-1638 cell

630-260-6572 office

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Nov 22, 2016 Nov 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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines