• 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 "Highlight" a layer in the Layers Panel using Javascript?

LEGEND ,
Feb 25, 2022 Feb 25, 2022

Copy link to clipboard

Copied

I want to set "Make/Release Clipping Mask" from the Layers flyout menu on a specific layer [0]. I've created an action that will toggle "Make/Release Clipping Mask" on and off, but for it to work at the "layer" level the layer must be highlighted in the layers panel. How can I do that in Javascript?

rcraighead_0-1645844887509.png

 

The artwork does not need to be selected, but for the top shape to mask the entire layer the layer must be highlighted, as you see above. If selected, this simple Action, run through Javascript, will do the trick:

rcraighead_1-1645844795238.png

app.doScript("MakeReleaseMask", "AI Actions_KM_2");

 

Thanks for any helps.

TOPICS
Scripting

Views

278

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 2 Correct answers

Community Expert , Feb 25, 2022 Feb 25, 2022

Hi @rcraighead, in your script can you try

app.activeDocument.activeLayer = myLayer;

where myLayer is a reference to your layer?

- Mark 

Votes

Translate

Translate
Guide , Feb 26, 2022 Feb 26, 2022

Not sure if this relevant to your situation, but creating and releasing a clipping mask can be done with one line of code.  A clipping mask is just a group with the "clipped" perperty set to true.

// select group
app.selection[0].clipped = true;

 

Votes

Translate

Translate
Adobe
Community Expert ,
Feb 25, 2022 Feb 25, 2022

Copy link to clipboard

Copied

Hi @rcraighead, in your script can you try

app.activeDocument.activeLayer = myLayer;

where myLayer is a reference to your layer?

- Mark 

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
Guide ,
Feb 26, 2022 Feb 26, 2022

Copy link to clipboard

Copied

Not sure if this relevant to your situation, but creating and releasing a clipping mask can be done with one line of code.  A clipping mask is just a group with the "clipped" perperty set to true.

// select group
app.selection[0].clipped = true;

 

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 ,
Feb 26, 2022 Feb 26, 2022

Copy link to clipboard

Copied

LATEST

Thank you both for you help.

 

"activeLayer" works only if I select and deselect artwork on a different layer first. Otherwise, the target layer does not get highlighted and "Make Clipping Mask" fails.

 

var aDoc = app.activeDocument;
aDoc.layers[0].hasSelectedArtwork = true;
aDoc.layers[0].hasSelectedArtwork = false;
aDoc.activeLayer = aDoc.layers[1];
app.doScript("MakeReleaseMask", "AI Actions_KM_2");
 
"clipping" works on a group but not a layer. Good to know though. Thanks!

var aDoc = app.activeDocument;
selection = null;
aDoc.activeLayer = aDoc.layers[1];
aDoc.layers[1].groupItems[0].selected = true;
app.selection[0].clipped = true;

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