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

Rename layer

Contributor ,
Nov 20, 2017 Nov 20, 2017

Copy link to clipboard

Copied

Good morning friends! How do I delete the current name of the active layer when replacing with the name entered in the text field of the dialog box? What is missing, where am I going wrong?

#target photoshop

var doc = activeDocument;

app.preferences.rulerUnits = Units.CM;

function layerNamer() {

var opts = new Object();

win=new Window("dialog","Replace Layer Name",[0,0,300,100],{resizeable:true,});

text01=win.add("statictext",[20,30,110,50] ,"Type something:")

text02=win.add("edittext",[110,30,250,50] ,"")

but_1=win.add("button",[110,58,197,78],"Replace Layer Name");

but_1.onClick = function() {

opts.replace = text02.text;

processDoc(opts);

}

win.center();

win.show();

};

if ( app.documents.length > 0) { layerNamer(); }

function processDoc(opts) {

     var find;

     if ( opts.global && !opts.ignore ) { find = new RegExp(opts.find,'gi'); }

      if ( !opts.global && !opts.ignore ) { find = new RegExp(opts.find,'i'); }

      var doc = app.activeDocument;

      recurseLayers(doc.layers);

      function recurseLayers(layObj) {

      for ( var i = 0; i < layObj.length; i++ ) {

               if ( find.test(layObj.name) )

                   {

                         if (layObj.kind == LayerKind.TEXT && !opts.txtLay) { continue; }

                         layObj.name = layObj.name.replace(find,opts.replace);

                    }

              if ( layObj.typename == 'LayerSet' )

                    { recurseLayers(layObj.layers); }

            }

      }

  };

TOPICS
Actions and scripting

Views

2.0K

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

Community Expert , Nov 21, 2017 Nov 21, 2017

If that's the case, just try this:

#target photoshop

var doc = activeDocument;

app.preferences.rulerUnits = Units.CM;

if ( app.documents.length > 0) { layerNamer(); }

function layerNamer() {

win=new Window("dialog","Replace Layer Name",[0,0,300,100],{resizeable:true,});

text01=win.add("statictext",[20,30,110,50] ,"Type something:")

text02=win.add("edittext",[110,30,250,50] ,"")

but_1=win.add("button",[110,58,197,78],"Replace Layer Name");

but_1.onClick = function() {

    try{

        app.activeDocument.acti

...

Votes

Translate

Translate
Adobe
Community Expert ,
Nov 20, 2017 Nov 20, 2017

Copy link to clipboard

Copied

What exactly are you trying to do? Normally you just specify a new name for the layer:

app.activeDocument.activeLayer.name = 'My new layer name'

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
Contributor ,
Nov 21, 2017 Nov 21, 2017

Copy link to clipboard

Copied

What exactly am I trying to do? I need to rename the layer name through the "edittext" field of the dialog. This script I posted only adds the new name to the name and does not remove the original name.

Screenshot_3.png

Ideally, it should look like image 3

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
Community Expert ,
Nov 21, 2017 Nov 21, 2017

Copy link to clipboard

Copied

Well, the reason I ask what exactly are you doing is that your script seems overly complicated to just replace the layer name. If you script worked as you say you want it to work, it would replace all the layer names with the same thing, as you are looping the script with a recursive function. Do you want ALL layers to have the same name?

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
Contributor ,
Nov 21, 2017 Nov 21, 2017

Copy link to clipboard

Copied

This script found right here in the adobe community! It is to rename only the selected layer nothing more, you have complete freedom to clean what is unnecessary, as long as it reaches the desired object. Thank you for your help!

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
Community Expert ,
Nov 21, 2017 Nov 21, 2017

Copy link to clipboard

Copied

If that's the case, just try this:

#target photoshop

var doc = activeDocument;

app.preferences.rulerUnits = Units.CM;

if ( app.documents.length > 0) { layerNamer(); }

function layerNamer() {

win=new Window("dialog","Replace Layer Name",[0,0,300,100],{resizeable:true,});

text01=win.add("statictext",[20,30,110,50] ,"Type something:")

text02=win.add("edittext",[110,30,250,50] ,"")

but_1=win.add("button",[110,58,197,78],"Replace Layer Name");

but_1.onClick = function() {

    try{

        app.activeDocument.activeLayer.name = text02.text;

        }

    catch(e){alert(e)}

    win.close();

}

win.center();

win.show();

};

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
Contributor ,
Nov 21, 2017 Nov 21, 2017

Copy link to clipboard

Copied

That's right, perfect! Thank you so much Chuck Uebele When I grow up, I want to be like you.

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
Engaged ,
Nov 22, 2017 Nov 22, 2017

Copy link to clipboard

Copied

Ps-Design  wrote

That's right, perfect! Thank you so much https://forums.adobe.com/people/Chuck+Uebele When I grow up, I want to be like you.

I've seen pictures of the "early Chuck", in social media, so cool that I'd like to be like him as a young man too, LOL.

(a bit of frivolousness never hurts    )

Davide Barranca - PS developer and author
www.ps-scripting.com

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
Community Expert ,
Nov 22, 2017 Nov 22, 2017

Copy link to clipboard

Copied

My life is/was not that glamorous, lol.

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 ,
Mar 18, 2018 Mar 18, 2018

Copy link to clipboard

Copied

LATEST

That script of original poster is most complex I ever seen - to change name of actively set layer! - too bad that can't work.

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