Skip to main content
Participant
February 9, 2023
Question

Duplicate layer in Illustrator

  • February 9, 2023
  • 1 reply
  • 186 views

trying to duplicate a layer in Illustrator using javascript. Found copyArtToLayer function on this community. But cannot seem to get it to work.  Even tried to place the items using 

ElementPlacement.PLACEATEND as the second paramter to the duplicate command.  If I can't do this in javascript, is there another method to copy layer with all of its contents to a new layer. Thank you.

 

#target Illustrator

 

var sourceLayer = doc.layers.getByName('txtpntLetter');
var destinationLayer = doc.layers.add();
destinationLayer.name = 'txtPathLetter';
copyArtToLayer(sourceLayer,destinationLayer);

function copyArtToLayer(srcLay, destLay) {
    var reLock = srcLay.locked ? true : false;
    var reHide = !srcLay.visible ? true : false;
    srcLay.locked = false;
    srcLay.visible = true;
    var item;

        for(var x = srcLay.pageItems.length -1; x>=0;x--) {
            item = srcLay.pageItems;
            item.duplicate(destLay);
        }
    srcLay.locked = reLock ? true : false;
    srcLay.visible = reHide ? false : true;
}
    This topic has been closed for replies.

    1 reply

    kglad
    Community Expert
    Community Expert
    February 9, 2023

    in the future, to find the best place to post your message, use the list here, https://community.adobe.com/

     

    p.s. i don't think the adobe website, and forums in particular, are easy to navigate, so don't spend a lot of time searching that forum list. do your best and we'll move the post if it helps you get responses.

     

    <moved from using the community>