How to Select Specific Layer Name

New Here ,
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

Adobe Community Professional
Correct answer by Manan Joshi | Adobe Community Professional

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

TOPICS
Actions and scripting, How to, Make It, Problem or error

Views

72

Likes

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

How to Select Specific Layer Name

New Here ,
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

Adobe Community Professional
Correct answer by Manan Joshi | Adobe Community Professional

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

TOPICS
Actions and scripting, How to, Make It, Problem or error

Views

73

Likes

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
Jan 05, 2021 0
Adobe Community Professional ,
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

Likes

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
Reply
Loading...
Jan 05, 2021 1
Participant ,
Jan 06, 2021

Copy link to clipboard

Copied

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.

 

Likes

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
Reply
Loading...
Jan 06, 2021 0