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

"Duplicate Layer" command in Script

Contributor ,
Aug 11, 2022 Aug 11, 2022

Copy link to clipboard

Copied

How to access the “Duplicate Layer” command in the layer panel with a script? I tried to find the relevant properties or methods in the script reference file, but I couldn't find, I also try to use the "ExecuteMenuCommand" methods, but I don't know what the corresponding command is. If there is no direct property or method, is there a script that can achieve the same function?

 

1111.jpg

TOPICS
Scripting

Views

378

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

correct answers 1 Correct answer

Community Expert , Aug 12, 2022 Aug 12, 2022

Hi,

If I am understand your question correctly, you want to duplicate multiple layers all together. If thsi is the case, then you need to select the layer each time before running the duplicateLayer method. Below is the snippet that will duplicate all layers in the active document.

function duplicateLayer() {
    var actionString = "/version 3" +
        "/name [ 5" +
        "	5365742031" +
        "]" +
        "/isOpen 1" +
        "/actionCount 1" +
        "/action-1 {" +
        "	/name [ 
...

Votes

Translate

Translate
Adobe
Community Expert ,
Aug 11, 2022 Aug 11, 2022

Copy link to clipboard

Copied

Hi,

You can use the action to duplicate the layers.

function duplicateLayer() {
    var actionString = "/version 3" +
        "/name [ 5" +
        "	5365742031" +
        "]" +
        "/isOpen 1" +
        "/actionCount 1" +
        "/action-1 {" +
        "	/name [ 15" +
        "		4475706c6963617465204c61796572" +
        "	]" +
        "	/keyIndex 0" +
        "	/colorIndex 0" +
        "	/isOpen 1" +
        "	/eventCount 1" +
        "	/event-1 {" +
        "		/useRulersIn1stQuadrant 0" +
        "		/internalName (ai_plugin_Layer)" +
        "		/localizedName [ 6" +
        "			53686f773a20" +
        "		]" +
        "		/isOpen 1" +
        "		/isOn 1" +
        "		/hasDialog 0" +
        "		/parameterCount 2" +
        "		/parameter-1 {" +
        "			/key 1836411236" +
        "			/showInPalette 4294967295" +
        "			/type (integer)" +
        "			/value 1" +
        "		}" +
        "		/parameter-2 {" +
        "			/key 1851878757" +
        "			/showInPalette 4294967295" +
        "			/type (ustring)" +
        "			/value [ 19" +
        "				4475706c69636174652053656c656374696f6e" +
        "			]" +
        "		}" +
        "	}" +
        "}" +
        "";

    var tmp = File(Folder.desktop + "/Set 1.aia");
    tmp.open('w');
    tmp.write(actionString);
    tmp.close();
    app.loadAction(tmp);
    app.doScript("Duplicate Layer", "Set 1", false);
    app.unloadAction("Set 1", "");
    tmp.remove();
}

duplicateLayer();

 

Make sure, layer is selected in the Layers panel to dupliacte it.

Best regards

Votes

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
Contributor ,
Aug 12, 2022 Aug 12, 2022

Copy link to clipboard

Copied

Hi @Charu Rajput 

This script work fine, thank you!

I want to make a loop to copy these layers in large numbers. It mean to execute this function in a loop. How do I realize it? Sorry, I know little about JS....

 

I tried below, but it can't work.

for (var i=1;i<4;i++)
{
    duplicateLayer();
}
 

Votes

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
Community Expert ,
Aug 12, 2022 Aug 12, 2022

Copy link to clipboard

Copied

Hi,

If I am understand your question correctly, you want to duplicate multiple layers all together. If thsi is the case, then you need to select the layer each time before running the duplicateLayer method. Below is the snippet that will duplicate all layers in the active document.

function duplicateLayer() {
    var actionString = "/version 3" +
        "/name [ 5" +
        "	5365742031" +
        "]" +
        "/isOpen 1" +
        "/actionCount 1" +
        "/action-1 {" +
        "	/name [ 15" +
        "		4475706c6963617465204c61796572" +
        "	]" +
        "	/keyIndex 0" +
        "	/colorIndex 0" +
        "	/isOpen 1" +
        "	/eventCount 1" +
        "	/event-1 {" +
        "		/useRulersIn1stQuadrant 0" +
        "		/internalName (ai_plugin_Layer)" +
        "		/localizedName [ 6" +
        "			53686f773a20" +
        "		]" +
        "		/isOpen 1" +
        "		/isOn 1" +
        "		/hasDialog 0" +
        "		/parameterCount 2" +
        "		/parameter-1 {" +
        "			/key 1836411236" +
        "			/showInPalette 4294967295" +
        "			/type (integer)" +
        "			/value 1" +
        "		}" +
        "		/parameter-2 {" +
        "			/key 1851878757" +
        "			/showInPalette 4294967295" +
        "			/type (ustring)" +
        "			/value [ 19" +
        "				4475706c69636174652053656c656374696f6e" +
        "			]" +
        "		}" +
        "	}" +
        "}" +
        "";

    var tmp = File(Folder.desktop + "/Set 1.aia");
    tmp.open('w');
    tmp.write(actionString);
    tmp.close();
    app.loadAction(tmp);
    app.doScript("Duplicate Layer", "Set 1", false);
    app.unloadAction("Set 1", "");
    tmp.remove();
}

var docRef = app.activeDocument
var _layers = docRef.layers;
app.executeMenuCommand('deselectall');
for (var l = 0; l < _layers.length; l++) {
    _layers[l].pageItems[0].selected = true;;
    duplicateLayer();
    app.executeMenuCommand('deselectall');
}
Best regards

Votes

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
Contributor ,
Aug 12, 2022 Aug 12, 2022

Copy link to clipboard

Copied

LATEST

Thanks @Charu Rajput 

 

It works very well.

Votes

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