Skip to main content
rcraighead
Legend
June 29, 2018
Question

Select Layer by Name (with or without objects)?

  • June 29, 2018
  • 1 reply
  • 413 views

I appropriated a script from this thread​ (thank you, pixxxel schubser).

It works as long as "myLayer" contains object(s) (even if they are locked and hidden). How can I change it to select the layer whether it has artwork or not?

I tried setting "hasSelectedArtwork" to "false", but no cigar.

var aDoc = app.activeDocument; 

aDoc.selection = null; 

try { 

    // be sure that top level layer with name "FINGERPRINT" with sublayer with name "Fingerprints" exists 

    var myLayer = aDoc.layers.getByName('FINGERPRINT').layers.getByName('Fingerprints'); 

    myLayer.hasSelectedArtwork = true; 

    } 

catch (e) { 

    alert("the layer doesn't exist"); 

    // do whatever you want 

    } 

Here's a sample file. The script will select "Fingerprints" layer unless the layer is empty.

Dropbox - Sample.ai

This topic has been closed for replies.

1 reply

Disposition_Dev
Legend
June 29, 2018

you could create a temporary object inside that layer if nothing already exists there. then use pixxxel's method to activate the layer. then delete the temporary object.