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

Renaming Sub-Layer

Advisor ,
Jun 28, 2017 Jun 28, 2017

Copy link to clipboard

Copied

I have this tiny script to rename a Sub-layer which works the first time I use it, then it adds to the existing sub-layer name when I run it after the first time.

var docRef = activeDocument;   
var sel = docRef.selection;   
for (var i=0; i < sel.length; i++)   
     sel.name = "CUTTER_B" + sel.name;

Any way to get this to consistently rename the sub-layer?

TOPICS
Scripting

Views

408

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
Adobe
Community Expert ,
Jun 28, 2017 Jun 28, 2017

Copy link to clipboard

Copied

Hi PrepressPro1

your code only works with page items - not with sublayers.

Unfortunately you didn't answer one month ago.

select by layer name

"… is this "sublayer" really a sublayer? Or a grouped item instead? …"

Same question again.

For selected page items you can do something like this

var docRef = activeDocument;

var sel = docRef.selection;

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

    var nme = sel.name.replace("CUTTER_B","");

    sel.name = "CUTTER_B" + nme;

}

Have fun

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
Advisor ,
Jun 28, 2017 Jun 28, 2017

Copy link to clipboard

Copied

It is an object on a sub-layer. Sorry for the hiatus in my posting. Projects get back burnered with the press of production work.  Thank you for your reply.

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
Advisor ,
Jun 28, 2017 Jun 28, 2017

Copy link to clipboard

Copied

Here is the sub-layer before running the scrip with the object selected.

Screen Shot 2017-06-28 at 2.07.30 PM.png

After the script is run.

Screen Shot 2017-06-28 at 2.08.00 PM.png

It still adds the name instead of replacing the 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
Community Expert ,
Jun 28, 2017 Jun 28, 2017

Copy link to clipboard

Copied

LATEST

That makes no difference. Same procedere as for page items

var docRef = activeDocument;

var sel = docRef.activeLayer;

//var sel = docRef.selection;

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

    //var nme = sel.name.replace("CUTTER_B","");

    var nme = sel.name.replace("CUTTER_B","");

    sel.name = "CUTTER_B" + nme;

    //sel.name = "CUTTER_B" + nme;

//}

Have fun

Or if I understood you wrong: Would you replace the whole name with Cutter_B?

Then: sel.name = "CUTTER_B"

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