Copy link to clipboard
Copied
Hello,
Is there a way to randomly sort artboards? The "Rearrange All Artboards" button provides a limited and orderly solution to this. But I need a solution that will sort randomly and differently every time it runs. Is this possible with a script?
Okay I'm still curious why you need to shuffle the artboard order, so feel free to give me a hint if you can. 🙂
Here's a script that will do what you want I think.
- Mark
UPDATE: you can find an improved version of my script here.
/*
Shuffle artboards
for Adobe Illustrator
by m1b
here: https://community.adobe.com/t5/illustrator-discussions/randomly-order-artboards/m-p/12692397
(Fisher Yates algorithm: sorry I can't find a source for this but not my code)
*/
...
Copy link to clipboard
Copied
I'm intrigued by this question. It is easy to shuffle artboards in a script (and then do something in that shuffled order), or do you need the artboards shuffled in the document? Can you explain more? I'm quite curious.
- Mark
Copy link to clipboard
Copied
Yes, I need the artboards to be shuffled in the document. I have dozens of documents containing at least 100 artboards. And each of them must be sorted randomly and irrelevantly in itself.
Copy link to clipboard
Copied
Okay I'm still curious why you need to shuffle the artboard order, so feel free to give me a hint if you can. 🙂
Here's a script that will do what you want I think.
- Mark
UPDATE: you can find an improved version of my script here.
/*
Shuffle artboards
for Adobe Illustrator
by m1b
here: https://community.adobe.com/t5/illustrator-discussions/randomly-order-artboards/m-p/12692397
(Fisher Yates algorithm: sorry I can't find a source for this but not my code)
*/
if (!Array.prototype.shuffle) Array.prototype.shuffle = (function (Object, max, min) {
"use strict";
// fisher-yates shuffle method
return function shuffle(picks) {
// randomises order of an array
if (this === null || this === undefined) throw TypeError("Array.prototype.shuffle called on null or undefined");
var p = picks === null || picks === undefined || picks == 0 ? this.length : picks;
var i = this.length, j = 0, temp;
while (i--) {
j = Math.floor(Math.random() * (i + 1));
// swap randomly chosen element with current element
temp = this[i];
this[i] = this[j];
this[j] = temp;
}
return this.slice(0, p);
};
})(Object, Math.max, Math.min);
var doc = app.activeDocument,
_artboards = [],
indices = [];
// make an array of existing artboards
for (var i = 0; i < doc.artboards.length; i++)
_artboards.push(doc.artboards[i]);
// copy the array for later
var deleteMeLater = _artboards.slice();
// shuffle using fisher yates method
_artboards.shuffle();
// add the artboards and match to existing
var a;
while (a = _artboards.pop()) {
var b = doc.artboards.add(a.artboardRect);
b.name = a.name;
b.rulerOrigin = a.rulerOrigin;
b.rulerPAR = a.rulerPAR;
b.showCenter = a.showCenter;
b.showCrossHairs = a.showCrossHairs;
b.showSafeAreas = a.showSafeAreas;
}
// delete the original artboards
while (a = deleteMeLater.pop())
a.remove();
Copy link to clipboard
Copied
Thanks a lot. This works great.
My goal is to produce complex scenes with different components (backgrounds, people, animals, objects, buildings and environmental factors, etc.). I will place each group of components in their correct positions in different documents. And I'll put it together in the final document. I aim to create 5,000 scenes with different variations. To produce more final documents, I needed sequential alternatives that were shuffled more and more quickly. Now I can achieve this much faster with the script you produced and a few simple steps.
Thanks again.
Copy link to clipboard
Copied
Interesting! Glad it worked for you.
Copy link to clipboard
Copied
is there is any script for reordering artboards by their position?
Copy link to clipboard
Copied
Sure. That script I posted could be modified to do that. For the sake of future people searching for this question, why don't you ask it as a new question? If you use the tag "scripting" I will see it and post the revised script. Or someone else will answer it. Explain what you mean by position: eg. top-most before bottom-most, and left-most before right-most?
- Mark
Copy link to clipboard
Copied
Hi Mark, Thank yà ou for your time.
I already asked as a new question this is the link: https://community.adobe.com/t5/illustrator-discussions/illustrator-script-to-renumber-reorder-the-ar...
Copy link to clipboard
Copied
Perfect. I hadn't seen it yet. But answered just now. Hope it works in your case.
- Mark
Copy link to clipboard
Copied
OK Thanks bro