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

How to efficiently check in script if an artboard is empty?

Explorer ,
Sep 28, 2020 Sep 28, 2020

Copy link to clipboard

Copied

I find I'm frequently writing scripts that operate across a large number of artboards (I'm working with documents full of icons, 1 icon per board = hundreds of artboards) and I've noticed a lot of artboard operations seem very slow in Illustrator scripting.

 

One common task I'm almost always having to do is to check first to see if an artboard actually has any content - and this can waste a lot of time the way I currently do it, can anyone suggest a generic faster method?

 

 for (var i = 0; i < app.activeDocument.artboards.length; i++) {
      
      app.activeDocument.selection = null;
      app.activeDocument.artboards.setActiveArtboardIndex(i);
      app.activeDocument.selectObjectsOnActiveArtboard();

      if (app.activeDocument.selection.length === 0) {
        //Empty!
      } else {
        //Not empty - do something!!
      }
}

 This approach isn't very performant, as it's activating each board in turn and then updating the document selection property, two slow tasks, just to check if there is any content.

 

Any suggestions for an alternative approach? 

TOPICS
Scripting

Views

419

Translate

Translate

Report

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
Adobe
Valorous Hero ,
Sep 29, 2020 Sep 29, 2020

Copy link to clipboard

Copied

Unfortunately, anything I can think of is still going to be slow, probably even worse! So, could there be any alternatives in your workflow where you could keep track of the artboards with some meta-data? Maybe if the script is very slow on 1000 artboards but can manage sets of 200 in a batch, hey..

Votes

Translate

Translate

Report

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
Explorer ,
Sep 29, 2020 Sep 29, 2020

Copy link to clipboard

Copied

Thanks @Silly-V that makes me a lot more confident that I'm not missing anything obvious.

 

Currently I start by running once through all the boards and classifying them, storing the results in a cache so I only ever have to do future operations on the required boards and not have to loop through them all again.

 

But thinking about it I could cache a lot more, the files are small and ram is cheap, I could cache all the objects on each board in memory against the artboard ID and then I'd be able to select any given artboard's contents by looping through the cache without activating the board or selecting it's contents. Or I could use a lot less memory and cache the object PageItem_UUIDs and reselect them that way, which I'd expect to be a bit slower.

 

It feels like swapping one set of loops for another, and doing stuff in ESTK that the framework offers a way to do natively, but it wouldn't be the first time that something like this turns out to be quicker than relying on the official method!

 

I'll run some tests and see if either approach makes a difference.

Votes

Translate

Translate

Report

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 ,
Sep 29, 2020 Sep 29, 2020

Copy link to clipboard

Copied

I'd be interested to hear what you discover! Sorry I couldn't help though. Your existing method is the way I've done it previously.

 

Mark

Votes

Translate

Translate

Report

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
Valorous Hero ,
Sep 30, 2020 Sep 30, 2020

Copy link to clipboard

Copied

LATEST

I don't know what you mean by caching in memory, except that going through pageItems in a loops tends to put them all into 'memory' causing slowness. But anyway, I just write a text file, they work super-fast!

Votes

Translate

Translate

Report

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 ,
Sep 30, 2020 Sep 30, 2020

Copy link to clipboard

Copied

same here, that's how I do it.

 

how many artboards are you dealing with?

how long does it take right now to be considered slow?

 

as Silly suggested there might be alternative on a different part of your process

Votes

Translate

Translate

Report

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