• 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 artboard batches, possible?

Explorer ,
Feb 22, 2021 Feb 22, 2021

Copy link to clipboard

Copied

Hi,

 

I'm aware scripts can solve lots of issues, but is there something that can rename artboards in batches of X (in my case, 8).

 

Or better still, increment (prefix) and rename by 10 every 8 artboards!? Example attached.

 

Any help would be greatly appreciated as I've used all the top renaming tools on the exported files, but none accommodate batches of X.

 

Thanks!

 

Screenshot 2021-02-22 at 14.19.37.png

 

TOPICS
Scripting

Views

614

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 , Feb 22, 2021 Feb 22, 2021

Hi,

Try following snippet

 

function main() {
    var doc = app.activeDocument;
    var artboards = doc.artboards;
    var incrementValue = 10;
    var initialValue = 120;
    var counter = 0
    for (var i = 0; i < artboards.length; i++) {
        var oldName = /_(.+)/.exec(artboards[i].name)[1]
        artboards[i].name = initialValue + "px_" + oldName;
        counter++;
        if (counter == 8) {
            counter = 0;
            initialValue = initialValue + incrementValue;
        }
  
...

Votes

Translate

Translate
Adobe
Guide ,
Feb 22, 2021 Feb 22, 2021

Copy link to clipboard

Copied

You want artboards 17-24 renamed "140px...", artboards 25-32 renamed "150px..." and so on?  

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
Explorer ,
Feb 22, 2021 Feb 22, 2021

Copy link to clipboard

Copied

Exactly

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 ,
Feb 22, 2021 Feb 22, 2021

Copy link to clipboard

Copied

Hi,

Try following snippet

 

function main() {
    var doc = app.activeDocument;
    var artboards = doc.artboards;
    var incrementValue = 10;
    var initialValue = 120;
    var counter = 0
    for (var i = 0; i < artboards.length; i++) {
        var oldName = /_(.+)/.exec(artboards[i].name)[1]
        artboards[i].name = initialValue + "px_" + oldName;
        counter++;
        if (counter == 8) {
            counter = 0;
            initialValue = initialValue + incrementValue;
        }
    }
}

main()

 

Best regards

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
Enthusiast ,
Feb 22, 2021 Feb 22, 2021

Copy link to clipboard

Copied

Hi Charu, do you know about the remainder operator?

function main() {
    var doc = app.activeDocument;
    var artboards = doc.artboards;
    var incrementValue = 10;
    var initialValue = 120;
    for (var i = 0; i < artboards.length; i++) {
        var oldName = /_(.+)/.exec(artboards[i].name)[1]
        artboards[i].name = initialValue + "px_" + oldName;
        initialValue = ((i + 1) % incrementValue == 0)
            ? initialValue + incrementValue
            : initialValue
    }
}

main()

Using it above, we don't explicitly need a counter variable that we increment and reset to 0 on the target increment:

12 % 5 // returns 2, 12 / 5 == 2 (with remainder of 2)
4 % 2 // returns 0, since 4 divided by 2 gives no remainder

Because i in our loop is essentially the same value as your counter (except subtracting 1), we can reliably know that (i + 1) % incrementValue hitting 0 means it's the start of a new increment (must be 10, 20, 30, or some multiple of whatever the custom increment is currently set as) and any loop afterward should increase their prefix value.

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 ,
Feb 22, 2021 Feb 22, 2021

Copy link to clipboard

Copied

@Inventsable Yes, I know 🙂

Thankyou for updating in more clearner way.

Best regards

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
Explorer ,
Feb 22, 2021 Feb 22, 2021

Copy link to clipboard

Copied

@Charu Rajput - Works lovely. Thank you very much... Speeds up my 15,000 artboard renaming!

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 ,
Feb 22, 2021 Feb 22, 2021

Copy link to clipboard

Copied

15K?!!!! that's insane

 

what do you do that needs 15000 artboards?

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
Explorer ,
Feb 23, 2021 Feb 23, 2021

Copy link to clipboard

Copied

LATEST

15k, yes indeed! That's what I thought when I 

 

A company is changing its branding. They are running social campaigns. We use an automation too to run the ads and switch in and out these PNGs based on variable data for the text, which these PNGs sit behind, so depending on how many text characters will depends on where they all fall. So we need to account for all possibilities, all lengths for all locations. 

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