Copy link to clipboard
Copied
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?
Copy link to clipboard
Copied
This block works as expected for me. Can you provide further details on how setDuplicateTemplate() is called?
Copy link to clipboard
Copied
I call it like so:
if ( z <= 1 || placementCount == 1 ) {
setIndividualTemplate(xi, placementClick);
} else {
setDuplicateTemplate(xi, placementClick, (placementClick -1));
}
the for loop is
for ( z = 1; z <= trackOrderQty; z++ )
Where trackOrderQty is all the orders.
Copy link to clipboard
Copied
I get the feeling that my code runs before things are executed it but that's impossible with ai right? Isn't it synchronously?
Copy link to clipboard
Copied
Are you able to provide (1) self-contained executable code and (2) a screenshot of a test document where the the problem has occurred?