Script to rename artboard batches, possible?

Community Beginner ,
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

112

Likes

Translate

Translate

Report

Report
Reply
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more

1 Correct Answer

Adobe Community Professional , Feb 22, 2021
Charu Rajput Adobe Community Professional , 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; } ...

Likes

Translate

Translate
Jump to answer Jump to answer
Enthusiast ,
Feb 22, 2021

Copy link to clipboard

Copied

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

Likes

Translate

Translate

Report

Report
Reply
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Phil5C41 AUTHOR
Community Beginner ,
Feb 22, 2021

Copy link to clipboard

Copied

Exactly

Likes

Translate

Translate

Report

Report
Reply
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Adobe Community Professional ,
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

Likes

Translate

Translate

Report

Report
Reply
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Engaged ,
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.

Likes

Translate

Translate

Report

Report
Reply
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Adobe Community Professional ,
Feb 22, 2021

Copy link to clipboard

Copied

@Inventsable Yes, I know 🙂

Thankyou for updating in more clearner way.

Best regards

Likes

Translate

Translate

Report

Report
Reply
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Phil5C41 AUTHOR
Community Beginner ,
Feb 22, 2021

Copy link to clipboard

Copied

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

Likes

Translate

Translate

Report

Report
Reply
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Adobe Community Professional ,
Feb 22, 2021

Copy link to clipboard

Copied

15K?!!!! that's insane

 

what do you do that needs 15000 artboards?

Likes

Translate

Translate

Report

Report
Reply
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Phil5C41 AUTHOR LATEST
Community Beginner ,
Feb 23, 2021

Copy link to clipboard

Copied

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. 

Likes

Translate

Translate

Report

Report
Reply
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more