app.documents[i].artboards[j] gets the jth artboard of the active document regardless of the value i
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)//testWe 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.
