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!
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;
}
...
Copy link to clipboard
Copied
You want artboards 17-24 renamed "140px...", artboards 25-32 renamed "150px..." and so on?
Copy link to clipboard
Copied
Exactly
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()
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.
Copy link to clipboard
Copied
Copy link to clipboard
Copied
@Charu Rajput - Works lovely. Thank you very much... Speeds up my 15,000 artboard renaming!
Copy link to clipboard
Copied
15K?!!!! that's insane
what do you do that needs 15000 artboards?
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.