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.
Any help would be wonderful.
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
...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.
Copy link to clipboard
Copied
The Layers to Artboards worked - so I took that and reversed everything and it worked:
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.
Copy link to clipboard
Copied
Booyah!!! works like a charm. made my weekend. thanks!