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

Writing a script to select the next artboard.

New Here ,
Mar 28, 2024 Mar 28, 2024

Copy link to clipboard

Copied

I need to write a script that simply selects the next artboard. 

I have tried a few scripts along the lines of: "var doc = app.activeDocument;
var artboards = doc.artboards;
var activeArtboard = doc.activeArtboard;
var nextArtboardIndex = activeArtboard.index + 1;
if (nextArtboardIndex < artboards.length) {
artboards[nextArtboardIndex].activate();
} else {
artboards[0].activate();
}"

But I get an Error 21: undefined is not an object.
Line: 4 -> var nextArtboarIndex = activeArtboard.index + 1;
 
Any help to correct this or if anyone can write a better script?
Much thanks in advance!
TOPICS
Scripting

Views

238

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

correct answers 1 Correct answer

Community Expert , Mar 28, 2024 Mar 28, 2024

Hi @Deny32888020duo3, here is one approach:

var doc = app.activeDocument;
var currentIndex = doc.artboards.getActiveArtboardIndex();
var nextIndex = (currentIndex + 1) % doc.artboards.length;

doc.artboards.setActiveArtboardIndex(nextIndex);

- Mark 

Votes

Translate

Translate
Adobe
Community Expert ,
Mar 28, 2024 Mar 28, 2024

Copy link to clipboard

Copied

Hi @Deny32888020duo3, here is one approach:

var doc = app.activeDocument;
var currentIndex = doc.artboards.getActiveArtboardIndex();
var nextIndex = (currentIndex + 1) % doc.artboards.length;

doc.artboards.setActiveArtboardIndex(nextIndex);

- 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
New Here ,
Mar 28, 2024 Mar 28, 2024

Copy link to clipboard

Copied

Thank you! This seems to sucessfully select the next artboard starting with 1. Though it does not change the selection the the Artboard panel it does select the next artboard on the screen!

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 ,
Mar 28, 2024 Mar 28, 2024

Copy link to clipboard

Copied

Yes I noticed that and even using app.redraw() didn’t update it. Still, it otherwise does the job.

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
Enthusiast ,
Mar 28, 2024 Mar 28, 2024

Copy link to clipboard

Copied

LATEST

It's an old bug. Probably with the advent of CC versions of Illustrator, because in CS5/CS6 the Artboards panel also changed.

My note about this: https://aiscripts.medium.com/active-artboard-display-120c69c48547

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