Skip to main content
New Participant
March 9, 2013
Answered

How to select active layer?

  • March 9, 2013
  • 2 replies
  • 2802 views

It appears that in order to resize the layer it has to be selected(from UI perspective) and active from API perspective. Otherwise I get error on any function call that this function is not supported.

So before resizing I do

var a = doc.artLayers.getByName("iPad");

app.activeDocument.activeLayer = a;

This doesn't visually change selected layer hence calling resize function fails after that. The only way to get it work, manually click on layer(any layer), then it works.

What is the proper way to resize layer without user interaction?

This topic has been closed for replies.
Correct answer

Hi Pashkatarakashka

Now try this code......

var docRef = app.activeDocument;

docRef.activeLayer=docRef.backgroundLayer;

var layerRef=docRef.layers.getByName("iPad");

docRef.activeLayer=layerRef;

layerRef.resize(120, 120, AnchorPosition.MIDDLECENTER);

-yajiv

2 replies

Kukurykus
Braniac
July 19, 2018

Probably I don't understand but your original code to select layer worked for me.

March 9, 2013

Hi Pashkatarakashka

Try this Code...

var docRef = app.activeDocument;

var layerRef=docRef.layers.getByName("iPad");

docRef.activeLayer=layerRef;

-yajiv

New Participant
March 9, 2013

Hi yajiv,

Still the same error that this function may not be available.

var docRef = app.activeDocument;

var layerRef=docRef.layers.getByName("iPad");

docRef.activeLayer=layerRef;

layerRef.resize(120, 120, AnchorPosition.MIDDLECENTER);

Again, if I click on any layer manually before running the script, it works. But if no layer is selected it fails.

Correct answer
March 9, 2013

Hi Pashkatarakashka

Now try this code......

var docRef = app.activeDocument;

docRef.activeLayer=docRef.backgroundLayer;

var layerRef=docRef.layers.getByName("iPad");

docRef.activeLayer=layerRef;

layerRef.resize(120, 120, AnchorPosition.MIDDLECENTER);

-yajiv