Quantcast
Channel: Adobe Community : Popular Discussions - Illustrator Scripting
Viewing all articles
Browse latest Browse all 12845

My Script works for exactly half of the group items I want it to act on, not sure exactly why.

$
0
0

var docRef = app.activeDocument;

 

var selectedObjects = docRef.selection;

 

 

if (selectedObjects.length > 1) {

 

 

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

var thisItem = selectedObjects[i];

 

 

thisItem.name = "RunPrep";

 

 

}

}

 

 

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

 

 

var thisItem1 = docRef.groupItems[i];

   

if(thisItem1.name == "RunPrep"){

 

 

var Layer2Move = docRef.layers.add();

 

 

Layer2Move.name = "Temp Layer";

 

 

var Layer2Move = docRef.layers.getByName ("Temp Layer"); 

 

 

thisItem1.moveToEnd(Layer2Move); 

   

var otherLayer = docRef.layers[1];

 

 

otherLayer.locked = true;

   

app.doScript ('PREP', 'SEP ACTIONS');

   

var poop = docRef.selection[0];

 

poop.name = "Prep has been run";

 

otherLayer.locked = false;

 

poop.moveToEnd(otherLayer);

 

Layer2Move.remove ();

 

}

}

 

 

 

 

So here is what is going on. My script will run a prep action. The prep action basically flattens the artwork. I am trying to do the prep action on each design I have selected individually so that it does not all get grouped together. It works exactly how I want it to......for exactly half of the selected objects no matter how many I have selected (or half +1 if it is an odd number).  Not sure why it only works for half haha but I am on the right track other than that. If anyone has an idea why that is happening, please let me know. Thanks in advance!!


Viewing all articles
Browse latest Browse all 12845

Trending Articles