Skip to main content
Known Participant
January 13, 2024
解決済み

I want to add Find Layer into my action

  • January 13, 2024
  • 返信数 3.
  • 524 ビュー

"Hello there, I'm having some problems with Photoshop. I'm trying to add the "Find Layer" function into my Action, but it doesn't seem to be recording when I use it. I aim to select all layers with the same first part of the name, such as noise1, noise2, noise3, etc. For example, my action would be: Find Layer -> noise (the name I'm choosing) -> select all layers.
I really need a solution for this. Is there another way to achieve my purpose, like a script or something? Please enlighten me. Thank you."

このトピックへの返信は締め切られました。
解決に役立った回答 Stephen Marsh

Full credit to @r-bin for the following scripts, I just made some minor adjustments:

 

Select Similar Layers from Prompt.jsx

 

 

/* 
Select Similar Layers from Prompt.jsx
Original script by r-bin
https://community.adobe.com/t5/photoshop-ecosystem-discussions/help-with-script-that-select-layers-based-on-string-then-move-selected-layers-to-specific-folder/m-p/12154839 
*/

var r_idx = new ActionReference();
var do_it = 0;

// by jazz-y
s2t = stringIDToTypeID;
(r = new ActionReference()).putProperty(s2t('property'), p = s2t('targetLayers'));
r.putEnumerated(s2t("document"), s2t("ordinal"), s2t("targetEnum"));
if (executeActionGet(r).getList(p).count) {
    var curLayer = activeDocument.activeLayer.name.replace(/(^\D+)(.+$)/, '$1');
} else {
    var curLayer = '';
}

var text = prompt("Layer name:", curLayer);

if (text != null)
    {
        var d = new ActionDescriptor();
        var r = new ActionReference();
        r.putEnumerated(stringIDToTypeID("layer"), stringIDToTypeID("ordinal"), stringIDToTypeID("targetEnum"));
        d.putReference(stringIDToTypeID("null"), r);
        executeAction(stringIDToTypeID("selectNoLayers"), d, DialogModes.NO);

    for (var i = 0; i < activeDocument.artLayers.length; i++) 
        if (activeDocument.artLayers[i].name.indexOf(text) >= 0) { r_idx.putIdentifier(stringIDToTypeID("layer"), activeDocument.artLayers[i].id); ++do_it; }

    if (do_it)
        {
        var d = new ActionDescriptor();
        d.putReference(stringIDToTypeID("null"), r_idx);
        executeAction(stringIDToTypeID("select"), d, DialogModes.NO);
        }

    //alert(do_it + " layers were selected");
    }

 

 

Select Similar Layers to Active Layer Name.jsx
 
/* 
Select Similar Layers to Active Layer Name.jsx
Original script by r-bin
https://community.adobe.com/t5/photoshop-ecosystem-discussions/help-with-script-that-select-layers-based-on-string-then-move-selected-layers-to-specific-folder/m-p/12154839 
https://community.adobe.com/t5/photoshop-ecosystem-discussions/select-layers-with-the-same-number-name/td-p/12964007
*/

var r_idx = new ActionReference();
var do_it = 0;

var selectedLayerTextPattern = activeDocument.activeLayer.name.match(/^\D+/);

if (selectedLayerTextPattern != null) {
    var d = new ActionDescriptor();
    var r = new ActionReference();
    r.putEnumerated(stringIDToTypeID("layer"), stringIDToTypeID("ordinal"), stringIDToTypeID("targetEnum"));
    d.putReference(stringIDToTypeID("null"), r);
    executeAction(stringIDToTypeID("selectNoLayers"), d, DialogModes.NO);
    
    // Top level layer groups
    for (var i = 0; i < activeDocument.layerSets.length; i++)
        if (activeDocument.layerSets[i].name.indexOf(selectedLayerTextPattern) >= 0) {
            r_idx.putIdentifier(stringIDToTypeID("layer"), activeDocument.layerSets[i].id);
            ++do_it;
        }
    

    // Top level layers
    for (var i = 0; i < activeDocument.artLayers.length; i++)
        if (activeDocument.artLayers[i].name.indexOf(selectedLayerTextPattern) >= 0) {
            r_idx.putIdentifier(stringIDToTypeID("layer"), activeDocument.artLayers[i].id);
            ++do_it;
        }
    
    if (do_it) {
        var d = new ActionDescriptor();
        d.putReference(stringIDToTypeID("null"), r_idx);
        executeAction(stringIDToTypeID("select"), d, DialogModes.NO);
    }

    //alert(do_it + " layers were selected");
}
 
Select Layers Named Noise.jsx
 
/* 
Select Layers Named Noise.jsx
Original script by r-bin
https://community.adobe.com/t5/photoshop-ecosystem-discussions/help-with-script-that-select-layers-based-on-string-then-move-selected-layers-to-specific-folder/m-p/12154839 
https://community.adobe.com/t5/photoshop-ecosystem-discussions/select-layers-with-the-same-number-name/td-p/12964007
*/

var r_idx = new ActionReference();
var do_it = 0;

var selectedLayerTextPattern = "Noise";

if (selectedLayerTextPattern != null) {
    var d = new ActionDescriptor();
    var r = new ActionReference();
    r.putEnumerated(stringIDToTypeID("layer"), stringIDToTypeID("ordinal"), stringIDToTypeID("targetEnum"));
    d.putReference(stringIDToTypeID("null"), r);
    executeAction(stringIDToTypeID("selectNoLayers"), d, DialogModes.NO);
    
    // Top level layer groups
    for (var i = 0; i < activeDocument.layerSets.length; i++)
        if (activeDocument.layerSets[i].name.indexOf(selectedLayerTextPattern) >= 0) {
            r_idx.putIdentifier(stringIDToTypeID("layer"), activeDocument.layerSets[i].id);
            ++do_it;
        }
    

    // Top level layers
    for (var i = 0; i < activeDocument.artLayers.length; i++)
        if (activeDocument.artLayers[i].name.indexOf(selectedLayerTextPattern) >= 0) {
            r_idx.putIdentifier(stringIDToTypeID("layer"), activeDocument.artLayers[i].id);
            ++do_it;
        }
    
    if (do_it) {
        var d = new ActionDescriptor();
        d.putReference(stringIDToTypeID("null"), r_idx);
        executeAction(stringIDToTypeID("select"), d, DialogModes.NO);
    }

    //alert(do_it + " layers were selected");
}

 

https://prepression.blogspot.com/2017/11/downloading-and-installing-adobe-scripts.html

 

返信数 3

Stephen Marsh
Community Expert
Stephen MarshCommunity Expert解決!
Community Expert
January 13, 2024

Full credit to @r-bin for the following scripts, I just made some minor adjustments:

 

Select Similar Layers from Prompt.jsx

 

 

/* 
Select Similar Layers from Prompt.jsx
Original script by r-bin
https://community.adobe.com/t5/photoshop-ecosystem-discussions/help-with-script-that-select-layers-based-on-string-then-move-selected-layers-to-specific-folder/m-p/12154839 
*/

var r_idx = new ActionReference();
var do_it = 0;

// by jazz-y
s2t = stringIDToTypeID;
(r = new ActionReference()).putProperty(s2t('property'), p = s2t('targetLayers'));
r.putEnumerated(s2t("document"), s2t("ordinal"), s2t("targetEnum"));
if (executeActionGet(r).getList(p).count) {
    var curLayer = activeDocument.activeLayer.name.replace(/(^\D+)(.+$)/, '$1');
} else {
    var curLayer = '';
}

var text = prompt("Layer name:", curLayer);

if (text != null)
    {
        var d = new ActionDescriptor();
        var r = new ActionReference();
        r.putEnumerated(stringIDToTypeID("layer"), stringIDToTypeID("ordinal"), stringIDToTypeID("targetEnum"));
        d.putReference(stringIDToTypeID("null"), r);
        executeAction(stringIDToTypeID("selectNoLayers"), d, DialogModes.NO);

    for (var i = 0; i < activeDocument.artLayers.length; i++) 
        if (activeDocument.artLayers[i].name.indexOf(text) >= 0) { r_idx.putIdentifier(stringIDToTypeID("layer"), activeDocument.artLayers[i].id); ++do_it; }

    if (do_it)
        {
        var d = new ActionDescriptor();
        d.putReference(stringIDToTypeID("null"), r_idx);
        executeAction(stringIDToTypeID("select"), d, DialogModes.NO);
        }

    //alert(do_it + " layers were selected");
    }

 

 

Select Similar Layers to Active Layer Name.jsx
 
/* 
Select Similar Layers to Active Layer Name.jsx
Original script by r-bin
https://community.adobe.com/t5/photoshop-ecosystem-discussions/help-with-script-that-select-layers-based-on-string-then-move-selected-layers-to-specific-folder/m-p/12154839 
https://community.adobe.com/t5/photoshop-ecosystem-discussions/select-layers-with-the-same-number-name/td-p/12964007
*/

var r_idx = new ActionReference();
var do_it = 0;

var selectedLayerTextPattern = activeDocument.activeLayer.name.match(/^\D+/);

if (selectedLayerTextPattern != null) {
    var d = new ActionDescriptor();
    var r = new ActionReference();
    r.putEnumerated(stringIDToTypeID("layer"), stringIDToTypeID("ordinal"), stringIDToTypeID("targetEnum"));
    d.putReference(stringIDToTypeID("null"), r);
    executeAction(stringIDToTypeID("selectNoLayers"), d, DialogModes.NO);
    
    // Top level layer groups
    for (var i = 0; i < activeDocument.layerSets.length; i++)
        if (activeDocument.layerSets[i].name.indexOf(selectedLayerTextPattern) >= 0) {
            r_idx.putIdentifier(stringIDToTypeID("layer"), activeDocument.layerSets[i].id);
            ++do_it;
        }
    

    // Top level layers
    for (var i = 0; i < activeDocument.artLayers.length; i++)
        if (activeDocument.artLayers[i].name.indexOf(selectedLayerTextPattern) >= 0) {
            r_idx.putIdentifier(stringIDToTypeID("layer"), activeDocument.artLayers[i].id);
            ++do_it;
        }
    
    if (do_it) {
        var d = new ActionDescriptor();
        d.putReference(stringIDToTypeID("null"), r_idx);
        executeAction(stringIDToTypeID("select"), d, DialogModes.NO);
    }

    //alert(do_it + " layers were selected");
}
 
Select Layers Named Noise.jsx
 
/* 
Select Layers Named Noise.jsx
Original script by r-bin
https://community.adobe.com/t5/photoshop-ecosystem-discussions/help-with-script-that-select-layers-based-on-string-then-move-selected-layers-to-specific-folder/m-p/12154839 
https://community.adobe.com/t5/photoshop-ecosystem-discussions/select-layers-with-the-same-number-name/td-p/12964007
*/

var r_idx = new ActionReference();
var do_it = 0;

var selectedLayerTextPattern = "Noise";

if (selectedLayerTextPattern != null) {
    var d = new ActionDescriptor();
    var r = new ActionReference();
    r.putEnumerated(stringIDToTypeID("layer"), stringIDToTypeID("ordinal"), stringIDToTypeID("targetEnum"));
    d.putReference(stringIDToTypeID("null"), r);
    executeAction(stringIDToTypeID("selectNoLayers"), d, DialogModes.NO);
    
    // Top level layer groups
    for (var i = 0; i < activeDocument.layerSets.length; i++)
        if (activeDocument.layerSets[i].name.indexOf(selectedLayerTextPattern) >= 0) {
            r_idx.putIdentifier(stringIDToTypeID("layer"), activeDocument.layerSets[i].id);
            ++do_it;
        }
    

    // Top level layers
    for (var i = 0; i < activeDocument.artLayers.length; i++)
        if (activeDocument.artLayers[i].name.indexOf(selectedLayerTextPattern) >= 0) {
            r_idx.putIdentifier(stringIDToTypeID("layer"), activeDocument.artLayers[i].id);
            ++do_it;
        }
    
    if (do_it) {
        var d = new ActionDescriptor();
        d.putReference(stringIDToTypeID("null"), r_idx);
        executeAction(stringIDToTypeID("select"), d, DialogModes.NO);
    }

    //alert(do_it + " layers were selected");
}

 

https://prepression.blogspot.com/2017/11/downloading-and-installing-adobe-scripts.html

 

GiangHg999作成者
Known Participant
January 14, 2024

I tried the code and it worked flawlessly. Thank you for supporting me. I hope someone in the community who has the same problem will find a solution now.

Stephen Marsh
Community Expert
Community Expert
January 14, 2024

You're welcome! Which of the three scripts was most useful for you to record into your action?

Stephen Marsh
Community Expert
Community Expert
January 13, 2024

What you are seeing is correct, the layer filters can't be recorded into an action. This will indeed require a script.

 

1. Do you wish to manually type the search term into an interface?

 

or

 

2. Or do you wish to have the search term as a static/embedded entry in the script?

 

or

 

3. Or do you wish to select the layer rather than typing, then have similar named layers selected?

 

John T Smith
Community Expert
Community Expert
January 13, 2024

You need to ask program questions in the forum for the program you are using
To ask in the forum for your program please start at https://community.adobe.com/
Moving from download and install to the Photoshop forum