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

Duplicate layer to multiple or all artboards

Community Beginner ,
Apr 23, 2021 Apr 23, 2021

Is there a way to duplicate a layer ("Layer > Duplicate Layer") onto multiple or all artboards instead of duplicating the layer individually for each artboard?

 

This would save me a ton of time!

7.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 2 Correct answers

Community Expert , Apr 25, 2021 Apr 25, 2021

I trust others might be able to get that into a lot fewer lines but you can give this a try:  

 

// duplicate one selected layer into all artboards;
// 2020, ue it at your own risk;
doStuff();
function doStuff () {
if (documents.length == 0) {return};
// get list of selected layers;
var ref = new ActionReference();
ref.putProperty (stringIDToTypeID ("property"), stringIDToTypeID ("targetLayersIDs"));
ref.putEnumerated( charIDToTypeID("Dcmn"), charIDToTypeID("Ordn"), charIDToTypeID("Trgt") ); 
va
...
Translate
Community Expert , Apr 08, 2024 Apr 08, 2024
quote

this is a great script' thank you very much (:

is there a way to change it to selected group instead of selected layer?

duplicate group to all other artboards


By @Lital5E82
if (documents.length == 0) {return};
// get list of selected layers;
var ref = new ActionReference();
ref.putProperty (stringIDToTypeID ("property"), stringIDToTypeID ("targetLayersIDs"));
ref.putEnumerated( charIDToTypeID("Dcmn"), charIDToTypeID("Ordn"), charIDToTypeID("Trgt") ); 
var targetLayersIDs = executeActionGet(ref
...
Translate
Adobe
Community Expert ,
Apr 23, 2021 Apr 23, 2021
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
Community Beginner ,
Apr 23, 2021 Apr 23, 2021

Thanks @c.pfaffenbichler . I did come across this.

 

I'm trying to duplicate Smart Objects for the most part. It seems this script copies and pastes; not duplicate. When the script is executed on a Smart Object, it pastes the selection on other artboards as pixels or raster images.

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
Community Expert ,
Apr 25, 2021 Apr 25, 2021

I trust others might be able to get that into a lot fewer lines but you can give this a try:  

 

// duplicate one selected layer into all artboards;
// 2020, ue it at your own risk;
doStuff();
function doStuff () {
if (documents.length == 0) {return};
// get list of selected layers;
var ref = new ActionReference();
ref.putProperty (stringIDToTypeID ("property"), stringIDToTypeID ("targetLayersIDs"));
ref.putEnumerated( charIDToTypeID("Dcmn"), charIDToTypeID("Ordn"), charIDToTypeID("Trgt") ); 
var targetLayersIDs = executeActionGet(ref).getList(stringIDToTypeID("targetLayersIDs"));
if (targetLayersIDs.count != 1) {
    alert ("select exactly one layer");
    return
};
// get current layer’s id;
var ref = new ActionReference();
ref.putProperty (stringIDToTypeID ("property"), stringIDToTypeID ("layerID"));
ref.putEnumerated( charIDToTypeID("Lyr "), charIDToTypeID("Ordn"), charIDToTypeID("Trgt") ); 
var layerID = executeActionGet(ref).getInteger(stringIDToTypeID("layerID"));
// collect artboards;
var theArtBoards = collectArtBoards ();
if (theArtBoards.length == 0) {
    alert ("no artboards");
    return
};
// process artboards;
for (var m = 0; m < theArtBoards.length; m++) {
// =======================================================
var idlayer = stringIDToTypeID( "layer" );
    var desc17 = new ActionDescriptor();
        var ref6 = new ActionReference();
        ref6.putEnumerated( idlayer, stringIDToTypeID( "ordinal" ), stringIDToTypeID( "targetEnum" ) );
    desc17.putReference( stringIDToTypeID( "null" ), ref6 );
    var idto = stringIDToTypeID( "to" );
        var ref7 = new ActionReference();
        ref7.putIndex( idlayer, theArtBoards[m][1] + m - 1 );
    desc17.putReference( idto, ref7 );
    desc17.putBoolean( stringIDToTypeID( "duplicate" ), true );
    desc17.putBoolean( stringIDToTypeID( "adjustment" ), false );
    desc17.putInteger( stringIDToTypeID( "version" ), 5 );
    var idlayerID = stringIDToTypeID( "layerID" );
        var list6 = new ActionList();
        list6.putInteger( 36 );
    desc17.putList( idlayerID, list6 );
executeAction( stringIDToTypeID( "move" ), desc17, DialogModes.NO );
};
// reselect original layer;
selectLayerByID (layerID, false);
};
////// collect layers with certain name //////
function collectArtBoards () {
// get number of layers;
    var ref = new ActionReference();
    ref.putProperty(stringIDToTypeID('property'), stringIDToTypeID('numberOfLayers'));
    ref.putEnumerated( charIDToTypeID("Dcmn"), charIDToTypeID("Ordn"), charIDToTypeID("Trgt") ); 
    var applicationDesc = executeActionGet(ref);
    var theNumber = applicationDesc.getInteger(stringIDToTypeID("numberOfLayers"));
// process the layers;
    var theLayers = new Array;
    for (var m = 0; m <= theNumber; m++) {
    try {
    var ref = new ActionReference();
    ref.putIndex( charIDToTypeID( "Lyr " ), m);
    var layerDesc = executeActionGet(ref);
    var layerSet = typeIDToStringID(layerDesc.getEnumerationValue(stringIDToTypeID("layerSection")));
    if (layerSet == "layerSectionStart") {
    var artBoardRect = layerDesc.getObjectValue(stringIDToTypeID("artboard")).getObjectValue(stringIDToTypeID("artboardRect"));
    var v01 = artBoardRect.getDouble(artBoardRect.getKey(0));
    var v02 = artBoardRect.getDouble(artBoardRect.getKey(1));
    var v03 = artBoardRect.getDouble(artBoardRect.getKey(2));
    var v04 = artBoardRect.getDouble(artBoardRect.getKey(3));
    var theName = layerDesc.getString(stringIDToTypeID('name'));
    var theID = layerDesc.getInteger(stringIDToTypeID('layerID'));
    var theIndex = layerDesc.getInteger(stringIDToTypeID('itemIndex'));
// collect if the rect values are not identical:
    if (v01 != v03 && v01 != v04) {theLayers.push([theName, theIndex, theID])}
    };
    }
    catch (e) {};
    };
    return theLayers
    };
////// based on code by mike hale and paul riggott //////
function selectLayerByID(index,add){ 
    add = undefined ? add = false:add 
    var ref = new ActionReference();
        ref.putIdentifier(charIDToTypeID("Lyr "), index);
        var desc = new ActionDescriptor();
        desc.putReference(charIDToTypeID("null"), ref );
           if(add) desc.putEnumerated( stringIDToTypeID( "selectionModifier" ), stringIDToTypeID( "selectionModifierType" ), stringIDToTypeID( "addToSelection" ) ); 
          desc.putBoolean( charIDToTypeID( "MkVs" ), false ); 
       try{
        executeAction(charIDToTypeID("slct"), desc, DialogModes.NO );
    }catch(e){
    alert(e.message); 
    }
    };

 

 

Edit: Here screenshots of my test-file; I tried to make sure Groups don’t cause problems, but there may be other scenarios I did not consider. 

Screenshot 2021-04-25 at 12.48.45.pngScreenshot 2021-04-25 at 12.48.56.png

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
Community Beginner ,
Apr 26, 2021 Apr 26, 2021

Thanks so much @c.pfaffenbichler for doing this.

 

I tried executing the script and received this error

Screen Shot 2021-04-26 at 9.43.42 AM.png

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
Community Expert ,
Apr 26, 2021 Apr 26, 2021

Could you please post a screenshot including the Layers Panel ar the time of the error? 

Or provide the file itself? 

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
Community Beginner ,
Apr 26, 2021 Apr 26, 2021

Ok. I've condensed the file size with reduced layers. The PSD can be downloaded here

https://drive.google.com/file/d/17_ObqDz9BwyKM_PT3WUMjLVTNWfzMSze/view?usp=sharing

 

I tried duplicating the layer, "CTA Button" and got that error.

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
Community Expert ,
Apr 26, 2021 Apr 26, 2021

The issue seems to hinge on the Groups being closed. 

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
Community Beginner ,
Apr 26, 2021 Apr 26, 2021

Ahhh, yes.

 

Wow, thanks so much @c.pfaffenbichler ! This is going to save me a ton of time.

Much appreciated!

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
Community Expert ,
Apr 26, 2021 Apr 26, 2021

Unfortunately I haven’t found a way to open the LayerSets yet, maybe someone else has an idea on this. 

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
Community Expert ,
Apr 07, 2024 Apr 07, 2024
quote

Unfortunately I haven’t found a way to open the LayerSets yet, maybe someone else has an idea on this. 


By @c.pfaffenbichler

 

 

I can't recall where I got this code (I'm usually pretty good at documenting the source):

 

#target photoshop

expandActiveLayerGroup();

function expandActiveLayerGroup() {
    if (app.activeDocument.activeLayer.typename == 'LayerSet' && app.activeDocument.activeLayer.layers.length > 0) {
        app.activeDocument.activeLayer = app.activeDocument.activeLayer.layers[0];
    }
}

 

And something from @jazz-y:

 

// Expand active group by jazz-y
var g = (ad = activeDocument).activeLayer;
if (g.typename == 'LayerSet' && g.layers.length) ad.activeLayer = g.layers[0];
ad.activeLayer = g;

 

There is also a link to some code from the late Mike Hale:

 

 

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
Community Expert ,
Apr 26, 2021 Apr 26, 2021

One work-around would be creating a Layer in the Artboard, duplicate it (this opens the collapsed Artboard), then remove the two nrely created Layers … but that is a pretty crude work-around and would slow things down a bit. 

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
Community Expert ,
Apr 26, 2021 Apr 26, 2021

Please try this – it should work with the Groups closed; and it should avoid duplicating to the current Artboard: 

 

// duplicate one selected layer into all artboards except the current one;
// 2020, ue it at your own risk;
doStuff();
function doStuff () {
if (documents.length == 0) {return};
// get list of selected layers;
var ref = new ActionReference();
ref.putProperty (stringIDToTypeID ("property"), stringIDToTypeID ("targetLayersIDs"));
ref.putEnumerated( charIDToTypeID("Dcmn"), charIDToTypeID("Ordn"), charIDToTypeID("Trgt") ); 
var targetLayersIDs = executeActionGet(ref).getList(stringIDToTypeID("targetLayersIDs"));
if (targetLayersIDs.count != 1) {
    alert ("select exactly one layer");
    return
};
// get current layer’s id;
var layerID = getLayerId ();
// collect artboards;
var theArtBoards = collectArtBoards ();
if (theArtBoards.length == 0) {
    alert ("no artboards");
    return
};
// get active layer’s artboard’s id;
var theLayer = activeDocument.activeLayer;
var thePar = theLayer.parent;
while (thePar.parent != activeDocument) {
    var thePar = thePar.parent;
};
activeDocument.activeLayer = thePar;
var artboardID = getLayerId ();
activeDocument.activeLayer = theLayer;
// process artboards;
var theAdd = 0;
for (var m = 0; m < theArtBoards.length; m++) {
// if not on the original artboard;
    if (theArtBoards[m][2] != artboardID) {
// =======================================================
var idlayer = stringIDToTypeID( "layer" );
    var desc17 = new ActionDescriptor();
        var ref6 = new ActionReference();
        ref6.putEnumerated( idlayer, stringIDToTypeID( "ordinal" ), stringIDToTypeID( "targetEnum" ) );
    desc17.putReference( stringIDToTypeID( "null" ), ref6 );
    var idto = stringIDToTypeID( "to" );
        var ref7 = new ActionReference();
        ref7.putIndex( idlayer, theArtBoards[m][1] + theAdd - 1 );
        theAdd++;
    desc17.putReference( idto, ref7 );
    desc17.putBoolean( stringIDToTypeID( "duplicate" ), true );
    desc17.putBoolean( stringIDToTypeID( "adjustment" ), false );
    desc17.putInteger( stringIDToTypeID( "version" ), 5 );
    var idlayerID = stringIDToTypeID( "layerID" );
        var list6 = new ActionList();
        list6.putInteger( 36 );
    desc17.putList( idlayerID, list6 );
executeAction( stringIDToTypeID( "move" ), desc17, DialogModes.NO );
// reselect original layer;
selectLayerByID (layerID, false);
    }
};
};
////// collect layers with certain name //////
function collectArtBoards () {
// get number of layers;
    var ref = new ActionReference();
    ref.putProperty(stringIDToTypeID('property'), stringIDToTypeID('numberOfLayers'));
    ref.putEnumerated( charIDToTypeID("Dcmn"), charIDToTypeID("Ordn"), charIDToTypeID("Trgt") ); 
    var applicationDesc = executeActionGet(ref);
    var theNumber = applicationDesc.getInteger(stringIDToTypeID("numberOfLayers"));
// process the layers;
    var theLayers = new Array;
    for (var m = 0; m <= theNumber; m++) {
    try {
    var ref = new ActionReference();
    ref.putIndex( charIDToTypeID( "Lyr " ), m);
    var layerDesc = executeActionGet(ref);
    var layerSet = typeIDToStringID(layerDesc.getEnumerationValue(stringIDToTypeID("layerSection")));
    if (layerSet == "layerSectionStart") {
    var artBoardRect = layerDesc.getObjectValue(stringIDToTypeID("artboard")).getObjectValue(stringIDToTypeID("artboardRect"));
    var v01 = artBoardRect.getDouble(artBoardRect.getKey(0));
    var v02 = artBoardRect.getDouble(artBoardRect.getKey(1));
    var v03 = artBoardRect.getDouble(artBoardRect.getKey(2));
    var v04 = artBoardRect.getDouble(artBoardRect.getKey(3));
    var theName = layerDesc.getString(stringIDToTypeID('name'));
    var theID = layerDesc.getInteger(stringIDToTypeID('layerID'));
    var theIndex = layerDesc.getInteger(stringIDToTypeID('itemIndex'));
// collect if the rect values are not identical:
    if (v01 != v03 && v01 != v04) {theLayers.push([theName, theIndex, theID])}
    };
    }
    catch (e) {};
    };
    return theLayers
    };
////// based on code by mike hale and paul riggott //////
function selectLayerByID(index,add){ 
    add = undefined ? add = false:add 
    var ref = new ActionReference();
        ref.putIdentifier(charIDToTypeID("Lyr "), index);
        var desc = new ActionDescriptor();
        desc.putReference(charIDToTypeID("null"), ref );
           if(add) desc.putEnumerated( stringIDToTypeID( "selectionModifier" ), stringIDToTypeID( "selectionModifierType" ), stringIDToTypeID( "addToSelection" ) ); 
          desc.putBoolean( charIDToTypeID( "MkVs" ), false ); 
       try{
        executeAction(charIDToTypeID("slct"), desc, DialogModes.NO );
    }catch(e){
    alert(e.message); 
    }
    };
////// get active layer’s id //////
function getLayerId () {
    var ref = new ActionReference();
    ref.putProperty (stringIDToTypeID ("property"), stringIDToTypeID ("layerID"));
    ref.putEnumerated( charIDToTypeID("Lyr "), charIDToTypeID("Ordn"), charIDToTypeID("Trgt") ); 
    return executeActionGet(ref).getInteger(stringIDToTypeID("layerID"));
};

 

 

Edit: The issue was a simple one after all; the pervious Script continuously duplicated the currently active Layer, meaning the duplicates, and when those were invisible the error occurred. 

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
New Here ,
Aug 27, 2021 Aug 27, 2021

Hi! I was looking for the same solution and this worked perfectly Adobe Photoshop CC 2021! Thanks! 

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
Community Beginner ,
Mar 14, 2023 Mar 14, 2023

Hey @c.pfaffenbichler 

Please forgive my ignorance. I'm looking for this same solution, but in the many years I've been a Photoshop user, I have no idea where to put this script. I've run actions for things I do repeatedly, but could you please explain how I would utilize this? It's a bummer this isn't integrated into the software like "step and repeat" in Indesign or "move" in illustrator where I can do it more than once. 

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
Community Expert ,
Mar 14, 2023 Mar 14, 2023

Save the code as a txt-file, change the extension to .jsx and copy it into Photoshop’s Presets/Scripts-Folder; after restarting Photoshop it should be available under File > Scripts and can be assigned a Shortcut or used in an Action. 

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
Community Beginner ,
Mar 14, 2023 Mar 14, 2023

thanks! I'll give it a shot. 

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
Community Beginner ,
Mar 14, 2023 Mar 14, 2023

file is grayed out when I try to browse from scripts menu. added .jsx but does the file name need to be formatted a certain way?

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
Community Expert ,
Mar 14, 2023 Mar 14, 2023
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
Community Expert ,
Mar 15, 2023 Mar 15, 2023

Did you save the code as a txt-file in TextEdit (or, if you are a Windows-user, the equivalent text editor)? 

And did you replace ».txt« with »,jsx«? 

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
New Here ,
Oct 27, 2023 Oct 27, 2023

Thank you!! Very helpful.

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
Community Beginner ,
Apr 07, 2024 Apr 07, 2024

this is a great script' thank you very much (:

is there a way to change it to selected group instead of selected layer?

duplicate group to all other artboards

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
Community Expert ,
Apr 08, 2024 Apr 08, 2024
quote

this is a great script' thank you very much (:

is there a way to change it to selected group instead of selected layer?

duplicate group to all other artboards


By @Lital5E82
if (documents.length == 0) {return};
// get list of selected layers;
var ref = new ActionReference();
ref.putProperty (stringIDToTypeID ("property"), stringIDToTypeID ("targetLayersIDs"));
ref.putEnumerated( charIDToTypeID("Dcmn"), charIDToTypeID("Ordn"), charIDToTypeID("Trgt") ); 
var targetLayersIDs = executeActionGet(ref).getList(stringIDToTypeID("targetLayersIDs"));
if (targetLayersIDs.count != 1) {
    alert ("select exactly one layer");
    return
};
// get current layer’s id;
var layerID = getLayerId ();
// collect artboards;
var theArtBoards = collectArtBoards ();
if (theArtBoards.length == 0) {
    alert ("no artboards");
    return
};
// get active layer’s artboard’s id;
var theLayer = activeDocument.activeLayer;
var thePar = theLayer.parent;
while (thePar.parent != activeDocument) {
    var thePar = thePar.parent;
};
activeDocument.activeLayer = thePar;
var artboardID = getLayerId ();
activeDocument.activeLayer = theLayer;
// process artboards;
for (var m = 0; m < theArtBoards.length; m++) {
// if not on the original artboard;
if (theArtBoards[m][2] != artboardID) {
// =======================================================
    var desc17 = new ActionDescriptor();
        var ref6 = new ActionReference();
        ref6.putEnumerated( stringIDToTypeID( "layer" ), stringIDToTypeID( "ordinal" ), stringIDToTypeID( "targetEnum" ) );
    desc17.putReference( stringIDToTypeID( "null" ), ref6 );
    var idto = stringIDToTypeID( "to" );
        var ref7 = new ActionReference();
        ref7.putIndex( stringIDToTypeID( "layer" ), getLayerIndexFromID(theArtBoards[m][2])-1 );
    desc17.putReference( idto, ref7 );
    desc17.putBoolean( stringIDToTypeID( "duplicate" ), true );
    desc17.putBoolean( stringIDToTypeID( "adjustment" ), false );
    desc17.putInteger( stringIDToTypeID( "version" ), 5 );
        var list6 = new ActionList();
        list6.putInteger( 36 );
    desc17.putList( stringIDToTypeID( "layerID" ), list6 );
executeAction( stringIDToTypeID( "move" ), desc17, DialogModes.NO );
// reselect original layer;
selectLayerByID (layerID, false);
    }
};
};
////// collect layers with certain name //////
function collectArtBoards () {
// get number of layers;
var ref = new ActionReference();
ref.putProperty(stringIDToTypeID('property'), stringIDToTypeID('numberOfLayers'));
ref.putEnumerated( charIDToTypeID("Dcmn"), charIDToTypeID("Ordn"), charIDToTypeID("Trgt") ); 
var applicationDesc = executeActionGet(ref);
var theNumber = applicationDesc.getInteger(stringIDToTypeID("numberOfLayers"));
// process the layers;
var theLayers = new Array;
for (var m = 0; m <= theNumber; m++) {
try {
var ref = new ActionReference();
ref.putIndex( charIDToTypeID( "Lyr " ), m);
var layerDesc = executeActionGet(ref);
var layerSet = typeIDToStringID(layerDesc.getEnumerationValue(stringIDToTypeID("layerSection")));
if (layerSet == "layerSectionStart") {
var artBoardRect = layerDesc.getObjectValue(stringIDToTypeID("artboard")).getObjectValue(stringIDToTypeID("artboardRect"));
var v01 = artBoardRect.getDouble(artBoardRect.getKey(0));
var v02 = artBoardRect.getDouble(artBoardRect.getKey(1));
var v03 = artBoardRect.getDouble(artBoardRect.getKey(2));
var v04 = artBoardRect.getDouble(artBoardRect.getKey(3));
var theName = layerDesc.getString(stringIDToTypeID('name'));
var theID = layerDesc.getInteger(stringIDToTypeID('layerID'));
var theIndex = layerDesc.getInteger(stringIDToTypeID('itemIndex'));
// collect if the rect values are not identical:
if (v01 != v03 && v01 != v04) {theLayers.push([theName, theIndex, theID])}
};
}
catch (e) {};
};
return theLayers
};
////// based on code by mike hale and paul riggott //////
function selectLayerByID(index,add){ 
add = undefined ? add = false:add 
var ref = new ActionReference();
    ref.putIdentifier(charIDToTypeID("Lyr "), index);
    var desc = new ActionDescriptor();
    desc.putReference(charIDToTypeID("null"), ref );
        if(add) desc.putEnumerated( stringIDToTypeID( "selectionModifier" ), stringIDToTypeID( "selectionModifierType" ), stringIDToTypeID( "addToSelection" ) ); 
        desc.putBoolean( charIDToTypeID( "MkVs" ), false ); 
    try{
    executeAction(charIDToTypeID("slct"), desc, DialogModes.NO );
}catch(e){
alert(e.message); 
}
};
////// get active layer’s id //////
function getLayerId () {
var ref = new ActionReference();
ref.putProperty (stringIDToTypeID ("property"), stringIDToTypeID ("layerID"));
ref.putEnumerated( charIDToTypeID("Lyr "), charIDToTypeID("Ordn"), charIDToTypeID("Trgt") ); 
return executeActionGet(ref).getInteger(stringIDToTypeID("layerID"));
};
////// get active layer’s id //////
function getLayerIndexFromID (theID) {
var ref = new ActionReference();
ref.putProperty (stringIDToTypeID ("property"), stringIDToTypeID ("itemIndex"));
ref.putIdentifier( charIDToTypeID("Lyr "), theID ); 
//ref.putEnumerated( charIDToTypeID("Lyr "), charIDToTypeID("Ordn"), charIDToTypeID("Trgt") ); 
return executeActionGet(ref).getInteger(stringIDToTypeID("itemIndex"));
};

Screenshot 2024-04-08 at 10.06.52.pngScreenshot 2024-04-08 at 10.07.02.png

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
Community Beginner ,
Apr 08, 2024 Apr 08, 2024

wow thats perfect

thank you so much

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
New Here ,
Jun 18, 2024 Jun 18, 2024

Can u help me? i get a error 

Error 30: Illegal 'return' outside of a function body.

Line: 1

->  if (documents.length == 0) {return};

 

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