• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Randomly order artboards.

Community Beginner ,
Jan 19, 2022 Jan 19, 2022

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?

TOPICS
Scripting

Views

734

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 , Jan 19, 2022 Jan 19, 2022

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)

*/

...

Votes

Translate

Translate
Adobe
Community Expert ,
Jan 19, 2022 Jan 19, 2022

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

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 Beginner ,
Jan 19, 2022 Jan 19, 2022

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.

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 ,
Jan 19, 2022 Jan 19, 2022

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

 

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 Beginner ,
Jan 19, 2022 Jan 19, 2022

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.

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 ,
Jan 19, 2022 Jan 19, 2022

Copy link to clipboard

Copied

Interesting! Glad it worked for you.

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 14, 2022 Feb 14, 2022

Copy link to clipboard

Copied

is there is any script for reordering artboards by their position?

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 15, 2022 Feb 15, 2022

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

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 15, 2022 Feb 15, 2022

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...

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 15, 2022 Feb 15, 2022

Copy link to clipboard

Copied

Perfect. I hadn't seen it yet. But answered just now. Hope it works in your case.

- Mark

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 15, 2022 Feb 15, 2022

Copy link to clipboard

Copied

LATEST

OK Thanks bro

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