Copy link to clipboard
Copied
"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."
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()).putPropert
...
Copy link to clipboard
Copied
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
Copy link to clipboard
Copied
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?
Copy link to clipboard
Copied
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
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
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
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
You're welcome! Which of the three scripts was most useful for you to record into your action?
Copy link to clipboard
Copied
i use script number 3, with the prefix name(can be change to fit multiple situation) i can add it into my action flow easily. So yeah that the most useful script to me, thankiu