Copy link to clipboard
Copied
Hello
I am trying to duplicate the layer by using script. But the duplicated layer is place at the beginning of layer order. I want the duplicated layer just above the layer.
I got this from forum.
var docRef = app.activeDocument;
with(docRef) {
var ll = docRef.activeLayer ;
var ln=ll.name;
var ol = layers.getByName(ln);
ll.visible = false;
var nl = layers.add();
nl.name = 'Duplicated Layer';
for (var a = ol.pageItems.length-1; a >= 0; a--) {
ol.pageItems.duplicate(nl, ElementPlacement.PLACEBEFORE);
nl.visible = true;
}
}
//~ ElementPlacement.PLACEBEFORE); // moves it above a group named 'my group' in the stacking order
//~ ElementPlacement.PLACEAFTER); // moves it below a group named 'my group' in the stacking order
//~ ElementPlacement.INSIDE); // moves it inside a group named 'my group', at the top of the stacking order
//~ ElementPlacement.PLACEATBEGINNING); // moves it inside a group named 'my group', at the top of the stacking order just like ElementPlacement.INSIDE
//~ ElementPlacement.PLACEATEND);
I duplicated Layer 2 and it place at the top. Strange.
Please help
Regards,
Karthi
1 Correct answer
Try this code...
...var docRef = app.activeDocument;
with(docRef) {
var ll = docRef.activeLayer ;
var n=docRef.layers.length;
x=ll.zOrderPosition;
var ln=ll.name;
var ol = layers.getByName(ln);
ll.visible = false;
var nl = layers.add();
nl.name = 'Duplicated Layer';
for (var a = ol.pageItems.length-1; a >= 0; a--) {
ol.pageItems.duplicate(nl, ElementPlacement.PLACEATBEGINNING);
nl.visible = true;
}
do
Explore related tutorials & articles
Copy link to clipboard
Copied
Try this code...
var docRef = app.activeDocument;
with(docRef) {
var ll = docRef.activeLayer ;
var n=docRef.layers.length;
x=ll.zOrderPosition;
var ln=ll.name;
var ol = layers.getByName(ln);
ll.visible = false;
var nl = layers.add();
nl.name = 'Duplicated Layer';
for (var a = ol.pageItems.length-1; a >= 0; a--) {
ol.pageItems.duplicate(nl, ElementPlacement.PLACEATBEGINNING);
nl.visible = true;
}
docRef.layers.getByName("Duplicated Layer").move(docRef.layers[n-x], ElementPlacement.PLACEAFTER);
}
- yajiv
Copy link to clipboard
Copied
Great..it is working good.. Thanks you

