Copy link to clipboard
Copied
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!!!
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-- ) {
Copy link to clipboard
Copied
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 )
};
};
Copy link to clipboard
Copied
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 )
};
};
Copy link to clipboard
Copied
I am looking to do this exact same thing, except in Photoshop, can you help me with that? Thanks!!! - Brandi
Copy link to clipboard
Copied
Copy link to clipboard
Copied
actually got it....in case anyone needs it.
Copy link to clipboard
Copied
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
Copy link to clipboard
Copied
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();
Copy link to clipboard
Copied
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?
Copy link to clipboard
Copied
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. 😃
Copy link to clipboard
Copied
Thank you I am trying to get that done now.
Ed Schrempf
847-489-1638 cell
630-260-6572 office
Copy link to clipboard
Copied
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.
Get ready! An upgraded Adobe Community experience is coming in January.
Learn more