Skip to main content
Known Participant
February 29, 2020
Answered

Automatisatin of duplication layers

  • February 29, 2020
  • 1 reply
  • 470 views

Hello,

How I can duplicate the layer by script ?

I have Layer X and how to make a copy of that ?

This topic has been closed for replies.
Correct answer pixxxelschubser

Like I wrote in your last thread, a layer doesn't have a duplicate method.

You have to go "the long way":

Create a new layer and duplicate all items from original layer to the new one.

// layers have no duplicate method - that's why 
// regards pixxxelschubser
var aDoc = app.activeDocument;
var dupLay = aDoc.layers.add();
dupLay.name = "Duplicat";
redraw();
var aLay = aDoc.layers.getByName("X"); // your existing layer name
var pI = aLay.pageItems;

for (k=pI.length-1; k>=0;k--) {
pI[k].duplicate(dupLay, ElementPlacement.PLACEATBEGINNING);
}

 

If that works for you

have fun

😉

1 reply

pixxxelschubser
Community Expert
pixxxelschubserCommunity ExpertCorrect answer
Community Expert
February 29, 2020

Like I wrote in your last thread, a layer doesn't have a duplicate method.

You have to go "the long way":

Create a new layer and duplicate all items from original layer to the new one.

// layers have no duplicate method - that's why 
// regards pixxxelschubser
var aDoc = app.activeDocument;
var dupLay = aDoc.layers.add();
dupLay.name = "Duplicat";
redraw();
var aLay = aDoc.layers.getByName("X"); // your existing layer name
var pI = aLay.pageItems;

for (k=pI.length-1; k>=0;k--) {
pI[k].duplicate(dupLay, ElementPlacement.PLACEATBEGINNING);
}

 

If that works for you

have fun

😉

BeffAuthor
Known Participant
February 29, 2020

Right, but in this way with one word you know what I mean 😉

Works great. Thank you.

From these "bricks" I was given from you I am making bigger constructions which are doing what I want.

 

Only the last question, I promise.