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

Script to Rename Artboards with Layer Names

Community Beginner ,
Mar 07, 2014 Mar 07, 2014

Copy link to clipboard

Copied

I'm looking to create a script to batch rename a number of artboards.

- I have 100 named layers.

- I have 100 artboards.

- I would like to rename the artboards to match the layer names.

- The layers are organized in the same descending orderas the artboards (ignoring the actual artboard names*).

- The topmost artboard (1 in the list) would be renamed "newspaper", the second artboard would be renamed "typewriter", the third artboard would be renamed "books", etc.

*in the example below the artboard named "Artboard 7" is actually the 6th artboard in list.

LayerNames-To-Artboards.png

Any help would be wonderful.

TOPICS
Scripting

Views

10.9K

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

Mentor , Mar 07, 2014 Mar 07, 2014

Hi sensibleworld, welcome to the forum.

 

For your case it should be pretty straight forward. The following little script snippet will rename the artboards to match the corresponding layer names as you described in your first post above. It only works if the number of layers and artboards match as shown and talked about in your above description of requirements.

 

if (app.documents.length == 0) {

    alert("No Open / Active Document Found");

} else {

    var doc = app.activeDocument;

    if (do

...

Votes

Translate

Translate
Adobe
Community Expert ,
Mar 20, 2021 Mar 20, 2021

Copy link to clipboard

Copied

"layers" is a collection of items, so when you want to access one, you have to pass in an index or a name.

 

In the error message you posted, it says that you're trying to access the value of "doc.layers.name". the layers collection doesn't have a name which is why you're getting the error. But besides, you don't want to be changing that anyway. you want to change the individual layers.

 

you can access a specific layer by zero based index, like so:

ab.name = doc.layers[0].name; //this would name the artboard based on the first layer in the document

ab.name = doc.layers[5].name; //this would name the artboard based on the SIXTH layer in the document

 

Or you can access a specific layer by name, like so:

ab.name = doc.layers["My Layer Name"].name;

 

long story short, when you're processing a collection of any kind (layers, groups, artboards, pageItems, textFrameItems, or arrays/objects that you yourself have created), you need to make sure you're referencing specific items of the collection rather than the whole collection by itself.

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
New Here ,
Dec 20, 2021 Dec 20, 2021

Copy link to clipboard

Copied

LATEST

The Layers to Artboards worked - so I took that and reversed everything and it worked:

if (app.documents.length == 0) {

alert("No Open / Active Document Found");

} else {

var doc = app.activeDocument;

if (doc.artboards.length == doc.layers.length && doc.layers.length == doc.artboards.length) {

for (var i = 0, l = doc.layers.length; i < l; i++) {

var ab = doc.layers[i];

ab.name = doc.artboards[i].name;

}

alert("Finished:\nRenaming of Layers to match Artboard names is complete");

} else {

alert("Opps: This wont work!\n The number of Layers and Artboards do not match");

}

}

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 ,
Mar 19, 2021 Mar 19, 2021

Copy link to clipboard

Copied

Hi shawn, try copying the script again. I just fixed the bug. It wasn't the author's bug just to clarify, it was the forum migration that messed scripts up.

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
New Here ,
Mar 19, 2021 Mar 19, 2021

Copy link to clipboard

Copied

Booyah!!! works like a charm. made my weekend. thanks!

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