• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
1

Renaming other than selected layer using Action Manager

LEGEND ,
Feb 24, 2018 Feb 24, 2018

Copy link to clipboard

Copied

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?

TOPICS
Actions and scripting

Views

672

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 1 Correct answer

People's Champ , Feb 24, 2018 Feb 24, 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.

Votes

Translate

Translate
Adobe
People's Champ ,
Feb 24, 2018 Feb 24, 2018

Copy link to clipboard

Copied

LATEST

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.

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