• 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

11.6K

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
Engaged ,
Mar 07, 2014 Mar 07, 2014

Copy link to clipboard

Copied

That's neat. What do you have so far in the way of a script or what questions/problems are you encountering?

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 Beginner ,
Mar 07, 2014 Mar 07, 2014

Copy link to clipboard

Copied

To be honest, I'm completely new to scripting (much more of a designer than a developer), and am hoping to either be pointed to a script that does something similar that I could fiddle with, or to have someone help me create it.

It was suggested that I should pose the question here (even though asking for someone to create the script for me is frowned upon). So, apologies for that

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
Mentor ,
Mar 07, 2014 Mar 07, 2014

Copy link to clipboard

Copied

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 (doc.artboards.length == doc.layers.length && doc.layers.length == doc.artboards.length) {

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

            var ab = doc.artboards[i];

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

        }

        alert("Finished:\nRenaming of Artboards to match Layer names is complete");

    } else {

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

    }

}

 

I hope it proves useful to your efforts and requirements. Again welcome to the forum.

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 Beginner ,
Mar 07, 2014 Mar 07, 2014

Copy link to clipboard

Copied

Worked like a charm! Thank you, thank you, thank 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
Mentor ,
Mar 07, 2014 Mar 07, 2014

Copy link to clipboard

Copied

You're welcome, glad it helped.

Hopefully it might be useful to someone else down the road as well with a similar situation.

Oops, I spelled oops (opps) wrong in my script 

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 Beginner ,
May 19, 2015 May 19, 2015

Copy link to clipboard

Copied

First of all, thank you for all of the help on this script (from over a year ago!).

I'm working on another project and a similar question popped up. I wonder if it's possible to tweak the script so that it ignored the order of the artboards/layers, but instead focused on the relationship between layer and artboard.

So, in this variation:

- Each artboard has a name.

- Each layer NEEDS a name.

- There are an equal number of layers and artboards.

- Only one layer "exists" on each artboard. (i.e. They share coordinates.)

- I would like to name the layer with the same name as its encompassing artboard.

Is this possible? Am I crazy? (They may not be mutually exclusive.)

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
Mentor ,
May 19, 2015 May 19, 2015

Copy link to clipboard

Copied

You probably should have started a new thread. 😉

sensibleworld wrote:

First of all, thank you for all of the help on this script (from over a year ago!).

I'm working on another project and a similar question popped up. I wonder if it's possible to tweak the script so that it ignored the order of the artboards/layers, but instead focused on the relationship between layer and artboard.

So, in this variation:

- Each artboard has a name.

- Each layer NEEDS a name.

- There are an equal number of layers and artboards.

- Only one layer "exists" on each artboard. (i.e. They share coordinates.)

- I would like to name the layer with the same name as its encompassing artboard.

Is this possible? Am I crazy? (They may not be mutually exclusive.)

If each layer has at least a single item on it (not empty) then the following should do what you described (if I understood correctly). It worked in my test of your described situation.

function artboardLayerNameMatch() {

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

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

    } else {

        var doc, i, l, ab, sel, n;

        doc = app.activeDocument;

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

            ab = doc.artboards;

            doc.artboards.setActiveArtboardIndex(i);

            doc.selectObjectsOnActiveArtboard();

            sel = doc.selection[0];

            sel.parent.name = ab.name;

            doc.selection = false;

        }

    }

}

artboardLayerNameMatch();

Hope it helps your efforts.

PS: As for being crazy, perhaps we all are to a certain degree, willingly living under the Adobe tyranny.

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 Beginner ,
May 19, 2015 May 19, 2015

Copy link to clipboard

Copied

Worked like a charm! Thank you so much.

And yeah, after I posted, I realized a new thread would have made more sense. It shall not happen again!

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
Mentor ,
May 19, 2015 May 19, 2015

Copy link to clipboard

Copied

You're welcome, glad it worked out for 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
Community Beginner ,
Apr 13, 2016 Apr 13, 2016

Copy link to clipboard

Copied

I wonder if someone could instruct me how to take this snippet and put it into a script I can put into Illustrator. I did copy / paste into script editor, but it doesn't seem to take in Adobe Illustrator 2015 CC. Help?

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
Community Expert ,
Apr 19, 2016 Apr 19, 2016

Copy link to clipboard

Copied

brucec11727021 wrote:

I wonder if someone could instruct me how to take this snippet and put it into a script I can put into Illustrator. I did copy / paste into script editor, but it doesn't seem to take in Adobe Illustrator 2015 CC. Help?

Thanks.

Option 1:

You can save the file as a .js or .jsx and access it via "File > Scripts > Other Script" then navigate to wherever you saved the script and run it that way. This option is best if you only plan on running the script once or twice.

Option 2:

You can save the file as a .js or .jsx into the application's scripts folder which will be located in: "Applications > Adobe Illustrator (Version number) > presets > en_us (or whatever language you've installed) > Scripts. Once you save the script into that folder, you'll have to re-launch illustrator. Then the script will show up in the "File > Scripts" list and you can execute the script from there. This option is best if you are going to use the script regularly as it will always be available in your File > Scripts menu.

Option 3:

You can paste the code into ExtendScript ToolKit and execute the code from inside the IDE. This is best if you are going to be modifying the code and you'll need to debug on the fly.

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 Beginner ,
Jul 29, 2017 Jul 29, 2017

Copy link to clipboard

Copied

Wondering if the reverse of the above script is possible?

The new scenario is:

  • Each layer has a name.
  • Each artboard NEEDS a name.
  • There are an equal number of layers and artboards.
  • Only one layer "exists" on each artboard. (i.e. They share coordinates.)
  • I would like to name the artboard with the same name as the layer that resides “on” it.

Here's the original for reference:

function artboardLayerNameMatch() { 

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

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

    } else { 

        var doc, i, l, ab, sel, n; 

        doc = app.activeDocument; 

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

            ab = doc.artboards

            doc.artboards.setActiveArtboardIndex(i); 

            doc.selectObjectsOnActiveArtboard(); 

            sel = doc.selection[0]; 

            sel.parent.name = ab.name; 

            doc.selection = false; 

        } 

    } 

artboardLayerNameMatch(); 

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 ,
Jul 31, 2017 Jul 31, 2017

Copy link to clipboard

Copied

While this is somewhat related to the original post, it would be a good idea to post a new topic with your question. You're more likely to get more answers and it will help anyone who has the same question in the future find the discussion.

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 Beginner ,
Jul 31, 2017 Jul 31, 2017

Copy link to clipboard

Copied

Right on, thanks! Just posted it here: Script to Rename Artboards Based on Layers (and Reverse)

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 ,
Aug 21, 2018 Aug 21, 2018

Copy link to clipboard

Copied

That script is a huge help - one question though:

How would I be able to modify this script so that it will rename the artboard to match the active layer  when there are fewer artboards than layers?

(if that's possible)

Thanks, guys!

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 ,
Aug 21, 2018 Aug 21, 2018

Copy link to clipboard

Copied

function test()

{

    var docRef = app.activeDocument;

    var artboards = docRef.artboards;

    var layers = docRef.layers;

    if(artboards.length < layers.length)

    {

        artboards[0].name = docRef.activeLayer.name;

    }

}

test();

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 ,
Jan 29, 2016 Jan 29, 2016

Copy link to clipboard

Copied

This works fantastically.  Thank you.  My question is, is there a way to reverse the order of the layers first?  I have my layers building from the bottom up on many files. 

1. Screen 1

then above that is the layer

2. Screen 2

So when I run this script it, names all of my artboards in reverse order.

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
Community Beginner ,
Jun 23, 2017 Jun 23, 2017

Copy link to clipboard

Copied

I realize I'm a little late with this reply but just in case anyone else might have the same question...

denisepotts  wrote

My question is, is there a way to reverse the order of the layers first?

Yes. In the Layers Panel, click on the first layer then shift-click on the last layer in order to 'highlight' them then go to the Layer Panel Options:

VTiyH.png

From there, choose 'Reverse Order':

wFyAb.png

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
Guest
May 23, 2019 May 23, 2019

Copy link to clipboard

Copied

This script works in reverse. When I used it, it took the first layer name and applied it to the last artboard.

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 ,
Aug 09, 2017 Aug 09, 2017

Copy link to clipboard

Copied

Hi,

My requirement is the same, but instead of layers it is the Layer Comps.

I'd like to give the Layer Comp names(PS) to the Art boards in Illustrator CC

Could someone please help with this! 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
New Here ,
Aug 21, 2018 Aug 21, 2018

Copy link to clipboard

Copied

Thank you !

Is that usable in Photoshop as well?

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 ,
Aug 21, 2018 Aug 21, 2018

Copy link to clipboard

Copied

i'm not sure, but i would guess that it is not. at least in it's current state.

i've never done much scripting for photoshop, but i don't believe that "artboards" is a property of the photoshop document object. so for that reason alone, it would probably fail.

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
Valorous Hero ,
Aug 21, 2018 Aug 21, 2018

Copy link to clipboard

Copied

In Ps the artboards are really funky - more of a repurposing of the layers mechanism. There are some scripts which come with Ps for artboard manipulation, they may be worth a look. Without having checked those out though, here's some findings:

#target photoshop

function test(){

    var doc = app.activeDocument;

    alert(doc.layers.length); // 2

   

    var thisLayer;

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

        thisLayer = doc.layers;

    }

    // first was [LayerSet Artboard 1]

    // 2nd was [ArtLayer Layer 2]

}

test();

So we can tell that the artboard is a layer set. However, so is a simple "group" of layers. If someone were to name their artboard "Group 1" then there's barely any difference as far as the code is concerned except that a group's default blend mode is blendMode.PASSTHROUGH and an artboard's is blendMode.NORMAL. And still it's possible for users to set all of those all different ways.

But for basic needs going through layersets and checking names of contained artLayers could be possible.

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

Stumbled across this script and its exactly what i need but doesnt seem to work in CC2020. I get an error saying doc.layers.name; can not be found. has anyone been able to get this to work in CC2020. its been a while since a post in this thread.

 

screenshot attached.

 

any help would be appreciated.

  Screen Shot 2021-03-19 at 6.33.55 PM.png

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