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

How to Select Specific Layer Name

Participant ,
Jan 05, 2021 Jan 05, 2021

Copy link to clipboard

Copied

I wish How to Select HFame Layer in Template

Capture.JPG

displayDialogs = DialogModes.NO; // OFF
var layer = app.activeDocument.activeLayer;
var layerName = layer.name;
cTID = function(s) { return app.charIDToTypeID(s); };
sTID = function(s) { return app.stringIDToTypeID(s); };
//for (var i = 0; i < numOfLayers-1 ; i++)
//{
// get a referenec to each layer as we loop over them
//var thisLayer = srcDoc.layers[i];
if(layerName=="HFrame")
{
alert("H");
var desc1 = new ActionDescriptor();
var ref1 = new ActionReference();
ref1.putName(cTID('Lyr '), "HFrame");
desc1.putReference(cTID('null'), ref1);
desc1.putBoolean(cTID('MkVs'), false);
var list1 = new ActionList();
list1.putInteger(21);
desc1.putList(cTID('LyrI'), list1);
executeAction(cTID('slct'), desc1, DialogModes.NO);
//break;
}
else
{
alert("V");
var desc1 = new ActionDescriptor();
var ref1 = new ActionReference();
ref1.putName(cTID('Lyr '), "VFrame");
desc1.putReference(cTID('null'), ref1);
desc1.putBoolean(cTID('MkVs'), false);
var list1 = new ActionList();
list1.putInteger(21);
desc1.putList(cTID('LyrI'), list1);
executeAction(cTID('slct'), desc1, DialogModes.NO);
//break;
}
// }

 

If Condition is false , I Can't Select HFrame in My Template.

Thanks in Advance

TOPICS
Actions and scripting

Views

432

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

Community Expert , Jan 05, 2021 Jan 05, 2021

Try the following snippet

 

try{
var lyr = app.documents[0].layers.getByName("HFrame")
app.documents[0].activeLayer = lyr
}
catch(e){alert("Could not locate layer")}

 

If you have multiple layers with the same name the above code will select only the first one in the collection.

-Manan

Votes

Translate

Translate
Adobe
Community Expert ,
Jan 05, 2021 Jan 05, 2021

Copy link to clipboard

Copied

Try the following snippet

 

try{
var lyr = app.documents[0].layers.getByName("HFrame")
app.documents[0].activeLayer = lyr
}
catch(e){alert("Could not locate layer")}

 

If you have multiple layers with the same name the above code will select only the first one in the collection.

-Manan

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 ,
Jan 06, 2021 Jan 06, 2021

Copy link to clipboard

Copied

LATEST

Thank you both for your suggestions. If Layer 2 is selected,  the function UnlockLayers selects Layer 1 when the script runs. When the scripts run again and Layer 1 reams selected. Is it possible to select Layer 2 when the script runs a second time?  Basically acting like a layer switch.

 

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