I'm attempting to duplicate a group and put in a specific layer. I'm encountering some errors so I'll explain. plcIx is always a current number like 2, 3, 4 etc. and itemLayer is the previous number so 2 - 1, etc. I call it like this: setDuplicateTemplate(xi, placementClick, (placementClick -1)); function setDuplicateTemplate(idx, plcIx, itemLayer) {
// here I select the previous layer where the items are.
var itemTemplateLayer = aDoc.layers.getByName("Placement" + itemLayer);
itemTemplateLayer.hasSelectedArtwork = true;
// I can visually see and am sure there are about 15 items but when I do the below alert it says length is 1;
alert(itemTemplateLayer.pathItems.length);
// I make the variable for the selected items... which is 15
var selected = aDoc.selection;
// I create the layer I want to place the items into
var mainTemplateLayer = aDoc.layers.getByName("Placement" + plcIx);
// I then loop through the selection and duplicate to the layer
for (var i = 0; i < selected.length; i++) {
selected[i].duplicate(mainTemplateLayer, ElementPlacement.PLACEATEND);
}
// I attempt to deselect the items so there will not be selected for the next one
aDoc.selection = [];
selected = [];
// anyway to position the items???
} After I run the above code each time I check the layer has multiple copies of the item. So in example in Placement 5, 6, 7 it's always duplicating. The duplicate is supposed to put the items in the new mainTemplateLayer but that's not happening. Any idea what I'm doing wrong?
... View more