Skip to main content
Participating Frequently
December 24, 2023
Answered

app.documents[i].artboards[j] gets the jth artboard of the active document regardless of the value i

  • December 24, 2023
  • 3 replies
  • 1486 views

In Illustrator, If you evaluate (app.documents[i].artboards[j]) with any value of (i), you will get the jth artboard of the active document regardless of the value of (i).

 

Even if you save the value of (app.documents[i].artboards[j]) in a variable and then change the active document, the value of the variable changes to the jth artboard of the currently active document.

Suppose we have three documents open and each one has one default artboard. You can run the following script:

var doc0;
var doc1;
var doc2;
var artboard;

doc0 = documents[0];
doc1 = documents[1];
doc2 = documents[2];
documents[0].activate();
$.writeln(doc0.artboards[0] === activeDocument.artboards[0]);//true
$.writeln(doc1.artboards[0] === activeDocument.artboards[0]);//true
$.writeln(doc2.artboards[0] === activeDocument.artboards[0]);//true
documents[1].activate()
$.writeln(doc0.artboards[0] === activeDocument.artboards[0]);//true
$.writeln(doc1.artboards[0] === activeDocument.artboards[0]);//true
$.writeln(doc2.artboards[0] === activeDocument.artboards[0]);//true
documents[2].activate();
$.writeln(doc0.artboards[0] === activeDocument.artboards[0]);//true
$.writeln(doc1.artboards[0] === activeDocument.artboards[0]);//true
$.writeln(doc2.artboards[0] === activeDocument.artboards[0]);//true

doc0.activate();
artboard = doc0.artboards[0];
artboard.name = 'test';
$.writeln(artboard.name)//test
doc1.activate();
$.writeln(artboard.name)//Artboard1 (name of the first artboard in doc1)
doc2.activate();
$.writeln(artboard.name)//Artboard1 (name of the first artboard in doc2)
doc0.activate();
$.writeln(artboard.name)//test

We need to activate a document to access its artboards and even if we save the artboard in a variable, after activating another document the variable points to the corresponding artboard in the newly activated document.  Isn't this possibly a bug?
At least Illustrator should give an error when we save an artboard in a variable and then access the variable after activating another document.


There is a similar post  from 2017 and I have studied it. I just wanted to expand upon it and discuss whether this behaviour is a bug or not.

This topic has been closed for replies.
Correct answer m1b

Hi @Omid236228649byk, It is definitely a bug. I have just lodged a bug report it. If you have time, you can vote on it.

- Mark

 

 

By the way, I like your equality test as a succinct way to highlight this bug:

1. open two documents

2. run this script:

if (app.documents[0].artboards[0] === app.documents[1].artboards[0])
    alert('What? The first artboard in two different Documents cannot be the same object!');

3 replies

CarlosCanto
Community Expert
Community Expert
December 25, 2023

I tested it using 2021 thru 2024, same results, so who knows when it started or if it has always been like this

Participating Frequently
December 25, 2023

I have only tested in Illustrator 2020 version 24.2.1 (64-bit) and I got this seeming bug.

femkeblanco
Legend
December 24, 2023

I agree, it's a bug. If you open two documents and run

var docs = app.documents;
docs[0].artboards[0].name = "AB1";
docs[1].artboards[0].name = "AB2";

the artboard in only the top document will change name (i.e. "artboards" points to the same collection).

m1b
Community Expert
m1bCommunity ExpertCorrect answer
Community Expert
December 24, 2023

Hi @Omid236228649byk, It is definitely a bug. I have just lodged a bug report it. If you have time, you can vote on it.

- Mark

 

 

By the way, I like your equality test as a succinct way to highlight this bug:

1. open two documents

2. run this script:

if (app.documents[0].artboards[0] === app.documents[1].artboards[0])
    alert('What? The first artboard in two different Documents cannot be the same object!');
Participating Frequently
December 25, 2023

I agree it is a bug because if they wanted only the artboards of the active document to be accessible, they didn't create a seperate artboards collection for every documents. Instead they could create a app.artboards collection.