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

Select group of layers by part of a name

Engaged ,
Apr 07, 2021 Apr 07, 2021

Copy link to clipboard

Copied

Is it possible to select group with a script if i know that name of that group always contains text, for example "TEST" but other part of group name is always changing (TEST1, TEST2, TEST3...)?

TOPICS
Actions and scripting

Views

1.2K

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

LEGEND , Apr 07, 2021 Apr 07, 2021

 

if (test = documents.length) {
	sTT = stringIDToTypeID, lngth = activeDocument.layerSets.length; (ref  = new ActionReference()).putProperty(sTT('property'), json = sTT('json'))
	ref.putEnumerated(sTT('layer'), sTT('ordinal'), sTT('targetEnum')), (evl = eval('(' + (dsc = executeActionGet(ref)).getString(json) + ')')).layers.length = lngth
	function slct(v) {test = (ref = new ActionReference()).putIdentifier(sTT('layer'), layerSet.id), dsc.putReference(sTT('null'), ref), executeAction(sTT('selec
...

Votes

Translate

Translate
Adobe
Community Expert ,
Apr 07, 2021 Apr 07, 2021

Copy link to clipboard

Copied

It is possible via Script. 

 

How frequent is the task for you? 

Enough so the Layers Panel’s name-Filer is not effivient enough? 

 

How does it need to be integrated in your workflow? 

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

Copy link to clipboard

Copied

// get index of layer/s of specified name and select layers;
// 2021, use it at your own risk;
if (app.documents.length > 0) {
main ();
};
////////////////////////////////////
function main () {
var ref = new ActionReference();
ref.putEnumerated( charIDToTypeID("Dcmn"), charIDToTypeID("Ordn"), charIDToTypeID("Trgt") ); 
var applicationDesc = executeActionGet(ref);
var theNumber = applicationDesc.getInteger(stringIDToTypeID("numberOfLayers"));
var theArray = new Array;
////// work through layers //////
for (var m = theNumber; m >= 0; m--) {
try {
var ref = new ActionReference();
ref.putIndex( charIDToTypeID( "Lyr " ), m);
var layerDesc = executeActionGet(ref);
var layerSet = typeIDToStringID(layerDesc.getEnumerationValue(stringIDToTypeID("layerSection")));
var theName = layerDesc.getString(stringIDToTypeID('name'));
var theID = layerDesc.getInteger(stringIDToTypeID('layerID'));
////////////////////////////////////
// if neither group start or end;
if (layerSet != "layerSectionEnd" /*&& layerSet != "layerSectionStart"*/) {
// if the name matches collect index;
if(theName.match(/test/i)) {theArray.push([m, theName])};
};
////////////////////////////////////
}
catch (e) {};
};
// select the results;
if (theArray.length > 0) {
selectLayerByIndex(theArray[0][0],false);
for (var x = 1; x < theArray.length; x++) {
selectLayerByIndex(theArray[x][0],true)
}
};
};
// by mike hale, via paul riggott;
// http://forums.adobe.com/message/1944754#1944754
function selectLayerByIndex(index,add){ 
add = undefined ? add = false:add 
var ref = new ActionReference();
    ref.putIndex(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); 
}
};

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
Engaged ,
Apr 07, 2021 Apr 07, 2021

Copy link to clipboard

Copied

I will use it several times during the day.

In fact my needs is to find and select the layer with name PPSTDGRP (it is constant) which is in the TEST group of layers. As I mentioned TEST group has sufix which will be diferent by user.

 

Can you help me how to select the mentioned layer with the script?

 

Thanks in advanced!

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

Copy link to clipboard

Copied

You need to amend the line 

if(theName.match(/test/i)) {theArray.push([m, theName])};

to reflect the actual string where »test« stands now. 

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
LEGEND ,
Apr 07, 2021 Apr 07, 2021

Copy link to clipboard

Copied

 

if (test = documents.length) {
	sTT = stringIDToTypeID, lngth = activeDocument.layerSets.length; (ref  = new ActionReference()).putProperty(sTT('property'), json = sTT('json'))
	ref.putEnumerated(sTT('layer'), sTT('ordinal'), sTT('targetEnum')), (evl = eval('(' + (dsc = executeActionGet(ref)).getString(json) + ')')).layers.length = lngth
	function slct(v) {test = (ref = new ActionReference()).putIdentifier(sTT('layer'), layerSet.id), dsc.putReference(sTT('null'), ref), executeAction(sTT('select'), dsc)}
	(function(v){while(test && v && lngth = v.length) {var lst = lngth - 1; if (/TEST[_-]?\d+/.test((layerSet = v[lst]).name)) return slct(); callee(v[lst].layers), v.length = lst}})(evl.layers)
}

 

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

Copy link to clipboard

Copied

Much more elegant! 

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
LEGEND ,
Apr 07, 2021 Apr 07, 2021

Copy link to clipboard

Copied

If you have topic name of Michael_L_Hale and Paul_Riggott they showed their tricks in, you can find changed link to, to reput that to the code in your earlier post 😉 They're restored! 🙂

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
Engaged ,
Apr 08, 2021 Apr 08, 2021

Copy link to clipboard

Copied

Thanks a lot. Just one more thing... group somethimes have special characters TEST_1 or TEST-1 and this script doesnt works when those special characters are between TEST and NUMBERS. Could you improve 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
LEGEND ,
Apr 08, 2021 Apr 08, 2021

Copy link to clipboard

Copied

I inserted [_-]?

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
Engaged ,
Apr 15, 2021 Apr 15, 2021

Copy link to clipboard

Copied

I encountered a new problem. I wanted to add an alert if there is no matching folder...

 

if (test = documents.length) {
	sTT = stringIDToTypeID, lngth = activeDocument.layerSets.length; (ref  = new ActionReference()).putProperty(sTT('property'), json = sTT('json'))
	ref.putEnumerated(sTT('layer'), sTT('ordinal'), sTT('targetEnum')), (evl = eval('(' + (dsc = executeActionGet(ref)).getString(json) + ')')).layers.length = lngth
	function slct(v) {test = (ref = new ActionReference()).putIdentifier(sTT('layer'), layerSet.id), dsc.putReference(sTT('null'), ref), executeAction(sTT('select'), dsc)}
	(function(v){while(test && v && lngth = v.length) {var lst = lngth - 1; if (/TEST[_-]?\d+/.test((layerSet = v[lst]).name)) return slct(); callee(v[lst].layers), v.length = lst}})(evl.layers)
}
else {
alert("There is no TEST folder");}

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
LEGEND ,
Apr 15, 2021 Apr 15, 2021

Copy link to clipboard

Copied

Over last character of my code add extra line:

 

	dsc.count - 2 && alert('There is no TEST folder!')

 

and just in case there's only background layer in the document change opening line to:

 

if (test = documents.length && ((lrs = activeDocument.layers).length > 1 || !lrs[0].isBackgroundLayer)) {

 

...or actually for consistency, first 2 lines to:

 

if (test = documents.length && lngth = activeDocument.layerSets.length) {
	sTT = stringIDToTypeID; (ref  = new ActionReference()).putProperty(sTT('property'), json = sTT('json'))

 

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
Engaged ,
Apr 17, 2021 Apr 17, 2021

Copy link to clipboard

Copied

@Kukurykus you will kill me 🙂 i got an idea, i want instead of alert to create test folder and implement some fuctions in case there is not test folder, but i dont know how to contintinus your script. Please help, i promise i will stop after 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
LEGEND ,
Apr 17, 2021 Apr 17, 2021

Copy link to clipboard

Copied

LATEST
if (test = documents.length && (aD = activeDocument).layerSets.length) {
	sTT = stringIDToTypeID; (ref  = new ActionReference()).putProperty(sTT('property'), json = sTT('json'))
	ref.putEnumerated(sTT('layer'), sTT('ordinal'), sTT('targetEnum')), (evl = eval('(' + (dsc = executeActionGet(ref)).getString(json) + ')')).layers.length = test
	function slct(v) {test = (ref = new ActionReference()).putIdentifier(sTT('layer'), layerSet.id), dsc.putReference(sTT('null'), ref), executeAction(sTT('select'), dsc)}
	(function(v){while(test && v && lngth = v.length) {var lst = lngth - 1; if (/TEST[_-]?\d+/.test((layerSet = v[lst]).name)) return slct(); callee(v[lst].layers), v.length = lst}})(evl.layers)
	dsc.count - 2 && (aD.activeLayer = aD.layers[0], (ref = new ActionReference()).putClass(sTT('layerSection')), (dsc1 = new ActionDescriptor()).putReference(sTT('null'), ref),
	(dsc2 = new ActionDescriptor()).putString(sTT('name'), 'TEST'), dsc1.putObject(sTT('using'), sTT('layerSection'), dsc2), executeAction(sTT('make'), dsc1))
}

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