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();