Skip to main content
Kukurykus
Legend
February 24, 2018
Answered

Renaming other than selected layer using Action Manager

  • February 24, 2018
  • 1 reply
  • 742 views

Simple scenario. We have 2 layers and background:

Layer 2

Layer 1

Background

If I wanted to rename "Layer 2" while it's not selected I could use Photoshop Object Model code:

activeDocument.layers[0].name = "new Name"

This way "Layer 2" doesn't have to get selected right before renaming, what saves time of performance.

If I want to rename selected "Layer 2" using Action Maanger I use this code:

function sTT(v) {return stringIDToTypeID(v)}

(ref1 = new ActionReference()).putEnumerated

(sTT('layer'), sTT('ordinal'), sTT('targetEnum'));

(dsc1 = new ActionDescriptor()).putReference(sTT('null'), ref1);

(dsc2 = new ActionDescriptor()).putString(sTT('name'), 'new Name')

dsc1.putObject(sTT('to'), sTT('layer'), dsc2)

executeAction(sTT('set'), dsc1, DialogModes.NO);

But if I want to do it for example by index I have to change this line:

(ref1 = new ActionReference()).putEnumerated(sTT('layer'), sTT('ordinal'), sTT('targetEnum'));

to this:

(ref1 = new ActionReference()).putIndex(sTT('layer'), 2);

Note that you count layers from down using AM, while from up with DOM (borth from 0). It's why there I used 0, and here 2.

Anyway when I use this code:

function sTT(v) {return stringIDToTypeID(v)}

(ref1 = new ActionReference()).putIndex(sTT('layer'), 2);

(dsc1 = new ActionDescriptor()).putReference(sTT('null'), ref1);

(dsc2 = new ActionDescriptor()).putString(sTT('name'), 'new Name')

dsc1.putObject(sTT('to'), sTT('layer'), dsc2)

executeAction(sTT('set'), dsc1, DialogModes.NO);

Always an active layer name gets renamed (not choosen in code), while when not any is selected then PS gets stuck!

This is common practise to do some operation with certain layer when it is not selected/active getting it by Index / Name / Indentifier, but for some reason doesn't work in the simplest part of working with layers! Note that DOM is based on AM, so there must be a way to change name of layer that is not active with AM, as when you do it with DOM then indicated layer is not beeing selected right before renaming! Well, I don't think that is bug in Action Manager, probably that code should look in this case different. Maybe that part with putObject should be changed? Can anyone tell me what is correct way to do it?

This topic has been closed for replies.
Correct answer r-bin

This is a bug in Photoshop. The name can not be changed if the layer is not active.

In the DOM model, the layer is also temporarily activated when it is renaming..

Moreover, In the DOM the layer becomes visible, and the other layers lose their selection if they have been selected.

1 reply

r-binCorrect answer
Legend
February 25, 2018

This is a bug in Photoshop. The name can not be changed if the layer is not active.

In the DOM model, the layer is also temporarily activated when it is renaming..

Moreover, In the DOM the layer becomes visible, and the other layers lose their selection if they have been selected.