Welcome Dialog

Welcome to the Community!

We have a brand new look! Take a tour with us and explore the latest updates on Adobe Support Community.


Duplicating items are doubling up.

Participant ,
Nov 19, 2021 Nov 19, 2021

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?

TOPICS
Scripting

Views

108

Likes

Translate

Translate

Report

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
Advocate ,
Nov 20, 2021 Nov 20, 2021

Copy link to clipboard

Copied

This block works as expected for me.  Can you provide further details on how setDuplicateTemplate() is called?

 

Untitled111.png

Likes

Translate

Translate

Report

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
Participant ,
Nov 20, 2021 Nov 20, 2021

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. 

Likes

Translate

Translate

Report

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
Participant ,
Nov 20, 2021 Nov 20, 2021

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?

Likes

Translate

Translate

Report

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
Advocate ,
Nov 21, 2021 Nov 21, 2021

Copy link to clipboard

Copied

LATEST

Are you able to provide (1) self-contained executable code and (2) a screenshot of a test document where the the problem has occurred?

Likes

Translate

Translate

Report

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