Skip to main content
Participant
September 1, 2017
Answered

documents[i].artboards.length not working (illustrator scripting)

  • September 1, 2017
  • 2 replies
  • 1418 views

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

This topic has been closed for replies.
Correct answer pixxxelschubser

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

2 replies

Participating Frequently
December 26, 2023

You can follow this post which discusses the same issue. And there is a bug report you can vote on.

pixxxelschubser
Community Expert
pixxxelschubserCommunity ExpertCorrect answer
Community Expert
September 1, 2017

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

Silly-V
Legend
September 1, 2017

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 + ".");

  }

pixxxelschubser
Community Expert
Community Expert
September 1, 2017

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 + ".");

}