Copy link to clipboard
Copied
Hi there!
I'm working on an illustrator extendscript where I have to get number of artboards for each opened document. The code may look like this
for ( var i=0 ; i<app.documents.length ; i++ ) {
alert(app.documents.artboards.length);
}
But each time I run this script, it returns the number of artboards for active document (only) each time.
for example if I've 3 documents opened ie. doc1 , doc2 , doc3
the number of artboards in doc1 is 1, doc2 is 4, and in doc3 is 2
and I'm currently working with doc2 ( doc2 is active)
then the script alerts 3 times saying: 4, 4 and 4 each time.
please help me
Also tell me if this code is correct or not
thanks in advance
update: I also tried alert( app.documents[1].artboards.length ); , It doesn't work either. having the same problem with this too (shows no: of artboards for active doc)
Tell me if I'm doing wrong
Hi sajidk54358625,
does this helps you on your way?
for ( var i=0; i<app.documents.length; i++ ) {
app.documents.activate();
alert(app.activeDocument.name);
alert(app.activeDocument.artboards.length);
}
Have fun
Copy link to clipboard
Copied
Hi sajidk54358625,
does this helps you on your way?
for ( var i=0; i<app.documents.length; i++ ) {
app.documents.activate();
alert(app.activeDocument.name);
alert(app.activeDocument.artboards.length);
}
Have fun
Copy link to clipboard
Copied
Interesting, it makes me think that artboards are indeed treated apart from other kinds of items in Illustrator documents. In the following lines, the only problematic item is the artboard count.
for ( var i=0 ; i < app.documents.length ; i++ ) {
alert("Name: " + app.documents.name + ". PathItems: " + app.documents.pathItems.length + ". Layers: " + app.documents.layers.length + ". Artboards: " + app.documents.artboards.length + ".");
}
Copy link to clipboard
Copied
IMHO artboards are only available in the active document. That's why activeDocument.artboards.length is possible - but not documents.artboards.length
for ( var i=0; i<app.documents.length; i++ ) {
app.documents.activate();
var aDoc = app.activeDocument;
alert("Name: " + aDoc.name + ". PathItems: " + aDoc.pathItems.length + ". Layers: " + aDoc.layers.length + ". Artboards: " + aDoc.artboards.length + ".");
}
Copy link to clipboard
Copied
thanks for your ideas! it really helped me
Copy link to clipboard
Copied
You can follow this post which discusses the same issue. And there is a bug report you can vote on.