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

Can you loop through a set number of open documents without closing them?

Contributor ,
Aug 08, 2022 Aug 08, 2022

Copy link to clipboard

Copied

Hi all,

Is that possible?

If I always have 8 documents open, I want to run the script on all 8, but without having to save and close each one - like a WHILE loop would do.

I just can't get this to work on more than one open file...

 

for (var i = 0; i < app.documents.length; i++) {
    var doc = app.activeDocument;
    var ABs = doc.artboards;
    ABs.setActiveArtboardIndex(176); //put KM variable in here
    doc.selectObjectsOnActiveArtboard();
    }

 Can anyone help at all? Many thanks, J

TOPICS
Scripting

Views

185

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

Guide , Aug 08, 2022 Aug 08, 2022

Add

doc.activate();

after var doc = app.documents[i];

Votes

Translate

Translate
Adobe
Community Expert ,
Aug 08, 2022 Aug 08, 2022

Copy link to clipboard

Copied

Hi @JustyR, change to

var doc = app.documents[i];

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
Contributor ,
Aug 08, 2022 Aug 08, 2022

Copy link to clipboard

Copied

Hmmm, I thought that would do it, but it still only works on the one open doc.

for (var i = 0; i < app.documents.length; i++) {
    var doc = app.documents[i];
    var ABs = doc.artboards;
    ABs.setActiveArtboardIndex(176); //put KM variable in here
    doc.selectObjectsOnActiveArtboard();
    }

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
Guide ,
Aug 08, 2022 Aug 08, 2022

Copy link to clipboard

Copied

Add

doc.activate();

after var doc = app.documents[i];

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
Contributor ,
Aug 08, 2022 Aug 08, 2022

Copy link to clipboard

Copied

LATEST

That did the trick. Many thanks to you both.

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