-
1. Re: Select layer by name.
KevinPowell_Art Oct 4, 2011 7:48 AM (in response to KevinPowell_Art)I would like to avoid dialog boxes to make this happen at creation.
-
2. Re: Select layer by name.
JJMack Oct 4, 2011 8:10 AM (in response to KevinPowell_Art)Search on getbyname in the scripting guides you will find documentation like this
The collections, as in this example, can be treated as arrays, which is useful for iteration. They also provide
methods to create their contained objects, and to access them by name:
var newLayer = activeDocument.artLayers.add(); // Create a new ArtLayer object
newLayer.name = "My Layer"; // name it for later reference
...
var layerRef = activeDocument.artLayers.getByName("My Layer");
so you would code somethinf like this
try { var layerRef = activeDocument.artLayers.getByName("PDF");}
catch(e){
alert("Document does not have the Required PDF layer");
var abort = true
}
-
3. Re: Select layer by name.
KevinPowell_Art Oct 4, 2011 9:49 AM (in response to JJMack)I had that information but I am trying to make the layer "active".
I can do basic actions with what you provided but what I am trying to do is set the layer to active so that other people using the script will not have to manually check to see if it is selected.
-
4. Re: Select layer by name.
Paul Riggott Oct 4, 2011 10:02 AM (in response to KevinPowell_Art)Here are a couple of examples...
activeDocument.activeLayer = activeDocument.artLayers.getByName('LayerName'); activeDocument.activeLayer = activeDocument.layerSets["LayerSetName"].artLayers.getByName ("LayerName"); -
5. Re: Select layer by name.
KevinPowell_Art Oct 4, 2011 10:05 AM (in response to Paul Riggott)perfect. Thank you.
-
6. Re: Select layer by name.
Michael L Hale Oct 5, 2011 6:56 AM (in response to KevinPowell_Art)If all the layers in the document are unique the function below will make a layer active by name regardless of where it is in the layer stack ( nested in groups or not )
function makeActiveLayerByName( lyrname ){ var desc = new ActionDescriptor(); var ref = new ActionReference(); ref.putName( charIDToTypeID( "Lyr " ), lyrname ); desc.putReference( charIDToTypeID( "null" ), ref ); desc.putBoolean( charIDToTypeID( "MkVs" ), false ); executeAction( charIDToTypeID( "slct" ), desc, DialogModes.NO ); }

