Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Duplicate layer just above the source layer by script

Guide ,
Jun 27, 2016 Jun 27, 2016

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);

Screen Shot 2016-06-28 at 11.20.59 AM.png

I duplicated Layer 2 and it place at the top. Strange.

Please help

Regards,

Karthi

TOPICS
Scripting
1.3K
Translate
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

correct answers 1 Correct answer

Engaged , Jun 28, 2016 Jun 28, 2016

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

...
Translate
Adobe
Engaged ,
Jun 28, 2016 Jun 28, 2016

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

Translate
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
Guide ,
Jun 28, 2016 Jun 28, 2016
LATEST

Great..it is working good.. Thanks you

Translate
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