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

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

Contributor ,
Nov 22, 2014 Nov 22, 2014

var docRef = app.activeDocument;

var selectedObjects = docRef.selection;

if (selectedObjects.length > 1) {

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

var thisItem = selectedObjects;

thisItem.name = "RunPrep";

}

}

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

var thisItem1 = docRef.groupItems;

   

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

TOPICS
Scripting
513
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

Community Expert , Nov 22, 2014 Nov 22, 2014

Because the index is changing as you work. Try starting with something like

for (i=docRef.groupItems.length-1; i=>0;  i--)

which goes backwards through the index and doesn't change the original array.

Translate
Adobe
Community Expert ,
Nov 22, 2014 Nov 22, 2014

Because the index is changing as you work. Try starting with something like

for (i=docRef.groupItems.length-1; i=>0;  i--)

which goes backwards through the index and doesn't change the original array.

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 Expert ,
Nov 22, 2014 Nov 22, 2014

expanding on what Larry said, when you start looping thru your objects, when you remove the top item (index 0), all other items move up in the stacking order, so pageItem[1], becomes pageItem[0], item[2], becomes item[1] and so on...so, on the next iteration, when you process your re-arranged item[1], you're actually dealing with your original item[2]...item[1] gets in fact skipped, explaining why your script works on every other item.

...but your script is too complicated, what's the purpose to move groups to a tempLayer? to be able to select it using your action?

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
Contributor ,
Nov 22, 2014 Nov 22, 2014
LATEST

Thanks Larry,

(i=docRef.groupItems.length-1; i>=0;  i--) appears to work, I just flipped the order of the greater than sign and the equal sign.

Thanks for explaining that to me Carlos, that makes sense.

Yea I know it's a lot. The tempLayer is being used the same as "Isolation mode". I do not know how to go in or out of Iso mode in script or an action so I just make a tempLayer and lock the original while the action performs. The Action is the combination of outlining strokes, flattening transparency, pathfinder merge, and it deletes paths with no fill. So it selects all and deletes everything with no fill, and I just want to narrow that down to just the design instead of the whole document.

Thanks again, both of you are very helpful. It works great!

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