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

Find Layers and Channels with same name

Explorer ,
Sep 01, 2023 Sep 01, 2023

Copy link to clipboard

Copied

Hi everyone! I'm experiencing some issues with automation here at the company when sending certain files. The biggest problem is duplicated layers and channels (with the same name). So, I would need a script that checks for their existence and alerts in some way. The layers could be highlighted in red, for example, while I think the channels would need to trigger an alert. It would be a final check before sending the file. Is it possible? 
Thanks!!

TOPICS
Actions and scripting

Views

128

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
Adobe
Community Expert ,
Sep 01, 2023 Sep 01, 2023

Copy link to clipboard

Copied

Wouldn’t it be better to avoid the duplication to begin with if they are the result of some automated processes? 

What are the Scripts/Actions involved in the creation of the duplicate Layers/Channels? 

 

Could you please provide a couple of exemplary files or at least post screenshots with the pertinent Panels (Toolbar, Layers, Options Bar, Channels, …) visible? 

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 ,
Sep 01, 2023 Sep 01, 2023

Copy link to clipboard

Copied

I'm thinking that such a script would be quite slow.

 

Have you searched the forum or web for one yet?

 

EDIT:

 

Can you post a screenshot of the layers panel? Is this only for top-level layers/layer sets – or do you also need to search inside layer groups and nested layer groups within layer groups?

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
Explorer ,
Sep 01, 2023 Sep 01, 2023

Copy link to clipboard

Copied

The duplicates are created by me and my coworkers, and sometimes by a lack of attention they ended up in the server....The server has a script that find those duplicates and send the files back to us, but i dont have access to it.
i am using a script, using the names of the layers, rename the first one (adding a suffix), and if it finds another, runs an action to mark it red, and then rename the first one (removes the suffix)...quite complex, but works. The problem im having most are with the channels....actually there is just one named "crop". If ther are 2 channels named crop, the server will identify and send it back. If we could find something to identify if there are 2 channels named crop, would be great. So i can add to the the scripts i have...Thanks for the answers!

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 ,
Sep 02, 2023 Sep 02, 2023

Copy link to clipboard

Copied

Could you please provide a couple of exemplary files or at least post screenshots with the pertinent Panels (Toolbar, Layers, Options Bar, Channels, …) visible? 

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 ,
Sep 02, 2023 Sep 02, 2023

Copy link to clipboard

Copied

Screenshot 2023-09-02 at 12.53.05.pngScreenshot 2023-09-02 at 12.53.14.png

// selectChannelsOfSameName;
// 2023, use it at your own risk;
if (app.documents.length > 0) {
////// collect layers //////
var theChannels = collectChannels ();
var theAdd = false;
for (var m = 0; m < theChannels.length; m++) {
    var thisOne = theChannels[m];
    for (var n = 0; n < theChannels.length; n++) {
        var thatOne = theChannels[n];
        if (m != n && thisOne[0] == thatOne[0]) {
            selectChannel (thatOne[1], theAdd);
            theAdd = true
        }
    };
};
};
////////////////////////////////////
////// collect channels //////
function collectChannels () {
// get number of layers;
var ref = new ActionReference();
ref.putEnumerated( charIDToTypeID("Dcmn"), charIDToTypeID("Ordn"), charIDToTypeID("Trgt") ); 
var applicationDesc = executeActionGet(ref);
var theNumber = applicationDesc.getInteger(stringIDToTypeID("numberOfChannels"));
// pixel dimensions;
var theWidth = applicationDesc.getUnitDoubleValue(stringIDToTypeID("width"));
var theHeight = applicationDesc.getUnitDoubleValue(stringIDToTypeID("height"));
var theRes = applicationDesc.getUnitDoubleValue(stringIDToTypeID("resolution"));
var thePixels = (theWidth*theRes/72)*(theHeight*theRes/72);
// process the channels;
var theChannels = new Array;
for (var m = 0; m <= theNumber; m++) {
try {
var ref = new ActionReference();
ref.putIndex(stringIDToTypeID( "channel" ), m);
var channelDesc = executeActionGet(ref);
// collect values;
var theName = channelDesc.getString(stringIDToTypeID('channelName'));
var theIndex = channelDesc.getInteger(stringIDToTypeID('itemIndex'));
var theID = channelDesc.getInteger(stringIDToTypeID('ID'));
/*var theColor = channelDesc.getObjectValue(stringIDToTypeID("alphaChannelOptions")).getObjectValue(stringIDToTypeID("color"));
if (channelDesc.hasKey(stringIDToTypeID('alphaChannelOptions')) == true) {
var theHistogram = channelDesc.getList(stringIDToTypeID('histogram'));*/
//var value0 = theHistogram.getInteger(0);
// if not completely black;
//if (value0 != thePixels) {
theChannels.push([theName, theIndex, theID])
//} else {}
//};
} catch (e) {};
};
return theChannels
};
////// select channel //////
function selectChannel (theIndex, theAdd) {
var desc6 = new ActionDescriptor();
var ref1 = new ActionReference();
ref1.putIndex( stringIDToTypeID( "channel" ), theIndex );
desc6.putReference( stringIDToTypeID( "null" ), ref1 );
desc6.putBoolean( stringIDToTypeID( "extend" ), true );
executeAction( stringIDToTypeID( "select" ), desc6, DialogModes.NO );
};

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 ,
Sep 02, 2023 Sep 02, 2023

Copy link to clipboard

Copied

And this one selects all Layers with identical names. 

Screenshot 2023-09-02 at 13.02.04.pngScreenshot 2023-09-02 at 13.02.22.png

// selectAllLayersOfSameNames;
// 2023, use it at your own risk;
if (app.documents.length > 0) {
////// collect layers //////
var theLayers = collectLayers ();
var theAdd = false;
for (var m = 0; m < theLayers.length; m++) {
    var thisOne = theLayers[m];
    for (var n = 0; n < theLayers.length; n++) {
        var thatOne = theLayers[n];
        if (m != n && thisOne[0] == thatOne[0]) {
            selectLayerByID (thatOne[1], theAdd);
            theAdd = true
        }
    };
};
};
////////////////////////////////////
////// collect layers //////
function collectLayers () {
// get number of layers;
var ref = new ActionReference();
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")));
var isBackground = layerDesc.getBoolean(stringIDToTypeID("background"));
// if group collect values;
if (layerSet != "layerSectionEnd" && layerSet != "layerSectionStart" && isBackground != true) {
var theName = layerDesc.getString(stringIDToTypeID('name'));
var theID = layerDesc.getInteger(stringIDToTypeID('layerID'));
//var theBounds = layerDesc.getObjectValue(stringIDToTypeID("bounds"));
//var theseBounds = [theBounds.getUnitDoubleValue(stringIDToTypeID("left")), theBounds.getUnitDoubleValue(stringIDToTypeID("top")), theBounds.getUnitDoubleValue(stringIDToTypeID("right")), theBounds.getUnitDoubleValue(stringIDToTypeID("bottom"))];
theLayers.push([theName, theID])
};
}
catch (e) {};
};
return theLayers
};
////// based on code by mike hale, via paul riggott //////
function selectLayerByID(id,add){
try {
add = undefined ? add = false:add 
var ref = new ActionReference();
ref.putIdentifier(charIDToTypeID("Lyr "), id);
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); 
}
} catch (e) {}
};

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 ,
Sep 05, 2023 Sep 05, 2023

Copy link to clipboard

Copied

@rrprec , what is the status of the issue? 

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
Explorer ,
Sep 08, 2023 Sep 08, 2023

Copy link to clipboard

Copied

Hi folks. Sorry for the delayed response. I'm currently swamped with work and haven't had a chance to test yet. I'll update the information here as soon as possible. Thank you!

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 ,
Sep 08, 2023 Sep 08, 2023

Copy link to clipboard

Copied

LATEST

Then let’s hope you have good shoes and arrive safely at the other side of the swamp. 

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