• 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 to multiple or all artboards

Community Beginner ,
Apr 23, 2021 Apr 23, 2021

Copy link to clipboard

Copied

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!

Views

4.7K

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 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
...

Votes

Translate

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
...

Votes

Translate

Translate
Adobe
Community Expert ,
Apr 23, 2021 Apr 23, 2021

Copy link to clipboard

Copied

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

Copy link to clipboard

Copied

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.

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

Copy link to clipboard

Copied

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

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

Copy link to clipboard

Copied

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

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

Copy link to clipboard

Copied

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

Or provide the file itself? 

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

Copy link to clipboard

Copied

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.

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

Copy link to clipboard

Copied

The issue seems to hinge on the Groups being closed. 

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

Copy link to clipboard

Copied

Ahhh, yes.

 

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

Much appreciated!

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

Copy link to clipboard

Copied

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

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

Copy link to clipboard

Copied

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:

 

 

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

Copy link to clipboard

Copied

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. 

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

Copy link to clipboard

Copied

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. 

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

Copy link to clipboard

Copied

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

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

Copy link to clipboard

Copied

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. 

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

Copy link to clipboard

Copied

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. 

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

Copy link to clipboard

Copied

thanks! I'll give it a shot. 

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

Copy link to clipboard

Copied

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?

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

Copy link to clipboard

Copied

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

Copy link to clipboard

Copied

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«? 

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

Copy link to clipboard

Copied

Thank you!! Very helpful.

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

Copy link to clipboard

Copied

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

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

Copy link to clipboard

Copied

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

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

Copy link to clipboard

Copied

LATEST

wow thats perfect

thank you so much

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

Copy link to clipboard

Copied

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