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

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

Community Beginner ,
Dec 24, 2023 Dec 24, 2023

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.

TOPICS
Bug , Scripting
968
Translate
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 , Dec 24, 2023 Dec 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!');
Translate
Adobe
Community Expert ,
Dec 24, 2023 Dec 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!');
Translate
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 ,
Dec 25, 2023 Dec 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.

Translate
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
Guide ,
Dec 24, 2023 Dec 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).

Translate
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 ,
Dec 25, 2023 Dec 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

Translate
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 ,
Dec 25, 2023 Dec 25, 2023

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

Translate
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 ,
Dec 25, 2023 Dec 25, 2023

Hey Carlos, the OP's link shows the same bug in 2017. But really, it may have been around since 2008 which, according to wikipedia, is when Illustrator introduced multiple artboards.

- Mark

Translate
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 ,
Dec 25, 2023 Dec 25, 2023

It's possible it's always behaved that way Mark, I'm surprised we didn't come across it before...

 

...which by the way, what are you trying to do Omid? are you stuck or did you find a workaround your current problem?

Translate
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 ,
Dec 26, 2023 Dec 26, 2023

In part of my script, I needed to copy something from two document A to document B and I needed to change the active document for copy and paste to work. I needed the size of the artboard from document A to create an artboard the same size in the document B. I saved the artboard object of document A and after activating document B,  that saved artboard object changed to artboard of document B and I could not use it to get size.

As a workaround,  I simply saved only the size of the artboard in a variable other than saving the artboard object itself.

Translate
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 ,
Dec 26, 2023 Dec 26, 2023

ok thanks for elaborating.

 

instead of copy/pasting I use duplicate(),

Translate
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 ,
Dec 26, 2023 Dec 26, 2023

Does duplicate() work between documents?

Also I needed to do "paste in place" to retain the position of items.

Translate
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 ,
Dec 26, 2023 Dec 26, 2023
quoteDoes duplicate() work between documents?



Yes, duplicate works between documents. It will duplicate with the same coordinates I think. So if the documents are set up the same the item will duplicate to the same place. If not, you might need to gather more info such as if document uses artboard coordinates, active artboard, document origin; things like that. 
- Mark

Translate
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 ,
Dec 26, 2023 Dec 26, 2023

I think the reason that this bug has not gotten much attention is that usually scripts work with one document and do not switch between two or more douments in the middle of execution.

Translate
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
Guide ,
Dec 26, 2023 Dec 26, 2023

I can confirm it exists in CS4 (2008).  By the way, has anyone curated a list of all the known bugs? 

Translate
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
Enthusiast ,
Dec 27, 2023 Dec 27, 2023

Scripting bugs are randomly found in SDK/Scripting Issues on Uservoice. If developers are not too lazy to post them there. Admittedly, I'm often lazy myself, because scripting developer issues on UV get less attention from the Adobe team. And that's demotivating. I recently complained about this on Slack (Adobe Illustrator Prerelease). I regularly describe bugs I find on my personal blog, but I don't always publish them on UV.

Translate
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 ,
Dec 27, 2023 Dec 27, 2023

I totally agree Sergey. Uservoice is an awkward platform to use (for one thing it is ridiculous that we cannot lodge bugs using our Adobe ID—instead we expect users to create a new account, which most won't do). In fact, I have come against this artboards bug many times (and used the Document.activate() workaround) bu until now I haven't been bothered to create a bug report. It's a shame it isn't super easy to lodge bugs. And it does feel like very few scripting bugs get fixed. But occasionally it happens.

- Mark

Translate
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
Enthusiast ,
Dec 27, 2023 Dec 27, 2023
LATEST

UV is aggressive with links. If you want to attach a link to a sample script or an article about a problem. I lost my account there once because the system banned me as a spammer. Reports posted from that account became anonymous. And no one at Adobe can restore the account because it is a third-party platform. I had to create a new account on UV, and now I'm afraid to post something unnecessary there and get banned again. Ugh!

Translate
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