Reply To: Object Style to New Layer

#103555

Haha, I had in the meantime 3 different samples and get different results, if I move forwards or backwards, but not any solution give the right results ;-)

First, you should remove your while loop. Second use a static array instead of your dynamic collection. This simplified example works for me in any solution:

var curDoc = app.activeDocument;
var objectStyleName = "Red Style";
var layerName = "Red Layer";    

var pItems = curDoc.pageItems.everyItem().getElements();
var nItems = pItems.length;

for (var i = 0; i < nItems; i++) {
  var curItem = pItems[i];
  if (curItem.appliedObjectStyle.name == objectStyleName && curItem.itemLayer.name != layerName) {             
    // move objects to layer
    curItem.itemLayer = curDoc.layers.itemByName(layerName);                     
  }
}

This article was last modified on May 5, 2018

Comments (0)

Loading comments...