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

Find and select layer by an specific word in its name script

Explorer ,
Jun 08, 2022 Jun 08, 2022

Copy link to clipboard

Copied

Hi everyone! I searched here in the community but couldn't find what I need or something I could change to what I need.

I would be grateful if anyone can help


I have some files, with several layers, but I need to select a specific layer in each of these files.

The names vary, but the ones I need have the final _final in the names.

 

Ex: Layer 123456_final, another layer, in another file, 5678_final, another abcd_final and so on. the names vary, but the _final is always the same within the files.

 

Is there any script that recognizes the _final and selects that layer regardless of the name that comes before it?

 

Thanks!

TOPICS
Actions and scripting

Views

397

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

Guide , Jun 08, 2022 Jun 08, 2022

more letters, but faster:

 

#target photoshop
s2t = stringIDToTypeID;
(ref = new ActionReference()).putProperty(s2t('property'), p = s2t('numberOfLayers'));
ref.putEnumerated(s2t('document'), s2t('ordinal'), s2t('targetEnum'));
var len = executeActionGet(ref).getInteger(p);
for (var i = 1; i <= len; i++) {
    (ref = new ActionReference()).putProperty(s2t('property'), p = s2t('name'));
    ref.putIndex(s2t('layer'), i);
    if ((/_final$/i).test(executeActionGet(ref).getString(p))) {
        (re
...

Votes

Translate

Translate
Adobe
Advocate ,
Jun 08, 2022 Jun 08, 2022

Copy link to clipboard

Copied

Just a hint... I asked something related in this thread, and the solution seems to be the 'split', which seems followed by regex...
https://community.adobe.com/t5/photoshop-ecosystem-discussions/script-to-delete-the-last-recent-laye...
I had asked to remove only Layer Comps starting with TMP_ (or some specific character, like – )

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 ,
Jun 08, 2022 Jun 08, 2022

Copy link to clipboard

Copied

It seems @Kukurykus and @r-bin were most active on above mentioned thread so I will mentioned them to draw their attention. Let me add and @c.pfaffenbichler @Stephen_A_Marsh 

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
Guide ,
Jun 08, 2022 Jun 08, 2022

Copy link to clipboard

Copied

more letters, but faster:

 

#target photoshop
s2t = stringIDToTypeID;
(ref = new ActionReference()).putProperty(s2t('property'), p = s2t('numberOfLayers'));
ref.putEnumerated(s2t('document'), s2t('ordinal'), s2t('targetEnum'));
var len = executeActionGet(ref).getInteger(p);
for (var i = 1; i <= len; i++) {
    (ref = new ActionReference()).putProperty(s2t('property'), p = s2t('name'));
    ref.putIndex(s2t('layer'), i);
    if ((/_final$/i).test(executeActionGet(ref).getString(p))) {
        (ref = new ActionReference()).putProperty(s2t('property'), p = s2t('layerID'));
        ref.putIndex(s2t('layer'), i);
        (r = new ActionReference()).putIdentifier(s2t("layer"), executeActionGet(ref).getInteger(p));
        (d = new ActionDescriptor()).putReference(s2t("target"), r);
        executeAction(s2t("select"), d, DialogModes.NO);
        break;
    }
}

 

or less letters, but slower:

 

lrs=[].slice.call((ad=activeDocument).layers)
while (l=lrs.shift()) if(/_final$/i.test(l.name)) {ad.activeLayer=l; break;}

 

 

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 ,
Jun 08, 2022 Jun 08, 2022

Copy link to clipboard

Copied

@rrprec  â€“ The first question that comes to mind is: what will you do with the selected layer?

 

The next question is – will there only be 1 layer ending in "_final" – or if there were multiple layers ending in "_final" do you need all of them to be selected? 

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 ,
Jun 11, 2022 Jun 11, 2022

Copy link to clipboard

Copied

Hi Stephen. Thanks for answering. There Will be lots of layers with that name. I will select one and run an action that changes the name. So i can loop the script to all layers um the file. 

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 Expert ,
Jun 11, 2022 Jun 11, 2022

Copy link to clipboard

Copied

Thanks, I was wondering "what was next"... Please share your final code.

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 ,
Jun 11, 2022 Jun 11, 2022

Copy link to clipboard

Copied

I use separated Scripts and actions. More files, but i think its easier If i have to change things later for my co workers and build new actions. 😉

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 ,
Jun 11, 2022 Jun 11, 2022

Copy link to clipboard

Copied

LATEST

Sure I get it, however, I was interested to see the code to loop over files with the name returned by the script provided by jazz-y. Although it may do the final layer processing, an action can't loop over the files from the script.

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