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

Select all content of indesign document for attaching script

New Here ,
Jul 07, 2014 Jul 07, 2014

Copy link to clipboard

Copied

I have a script that does some useful operation for my document. But it always need have selected part of document, like

if( app.selection.length > 0 ) ...

Could you ask me how can I select all pages from indesign document. I can have a lot of pages. And I have a lot of .indd files
I tried use app.activeDocument.pages.item(0).allPageItems; but it isn't effect even for page =(

Maybe I can use 'for' loop but maybe there is some function for selecting all document, not only one page

Thanks

TOPICS
Scripting

Views

1.4K

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

Advocate , Jul 07, 2014 Jul 07, 2014

Of course:

myPages = app.activeDocument.pages.everyItem().getElements(); // array of references to pages of document

for (var k = myPages.length - 1; k >= 0; k--) {

   myItems = myPages.allPageItems;

   for (var j = myItems.length - 1; j >= 0; j--) {

       processItem(myItems);

   }

}

This processes everything from back to front which is usually the safe approach and is potentially a little bit quicker than going the other way.

You still need to write the processItem function.

Dave

Votes

Translate

Translate
Advocate ,
Jul 07, 2014 Jul 07, 2014

Copy link to clipboard

Copied

A script does not have to make a selection to operate on objects, and indeed, you can't select beyond either the current spread or current text range. Selecting is what you have to do to use the user interface but a script can operate on any objects you can address ... as you seem to understand from the snippet of code you provided.

app.activeDocument.pages.item(0).allPageItems should have given you an array of all the page items on the first page of the active document, but because it's an array you have to loop through the items working on each one:

myItems = app.activeDocument.pages[0].allPageItems;

for (var j = myItems.length - 1; j >= 0; j--) {

   processItem(myItems);

}

where processItem is a function that does whatever you want to do to each item.

Dave

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 ,
Jul 07, 2014 Jul 07, 2014

Copy link to clipboard

Copied

Can I use 'for' loop for iterating all pages in document? How can I get number of pages for this operation, tell me please

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
Advocate ,
Jul 07, 2014 Jul 07, 2014

Copy link to clipboard

Copied

Of course:

myPages = app.activeDocument.pages.everyItem().getElements(); // array of references to pages of document

for (var k = myPages.length - 1; k >= 0; k--) {

   myItems = myPages.allPageItems;

   for (var j = myItems.length - 1; j >= 0; j--) {

       processItem(myItems);

   }

}

This processes everything from back to front which is usually the safe approach and is potentially a little bit quicker than going the other way.

You still need to write the processItem function.

Dave

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 ,
Jul 14, 2014 Jul 14, 2014

Copy link to clipboard

Copied

Hi, Dave Saunders


I run this and get an error the error soruce : processItem(myItems);

can someone tell me why?

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 ,
Dec 03, 2014 Dec 03, 2014

Copy link to clipboard

Copied

Hi

I have a problem with this script

It does not work with element outside of the page:

ELEMENTS OUTSIDE THE PAGE:(does not get all elements..)

ELEMENTS_OUTSIDE_DE_PAGE.jpg

ELEMENTS_INDIDE_THE_PAGE(working)

ELEMENTS_INSIDE_DE_PAGE.jpg

Thanks

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 ,
Dec 03, 2014 Dec 03, 2014

Copy link to clipboard

Copied

LATEST

It is look like I found the solution:

myItems = app.activeDocument.pageItems.everyItem().getElements();

for (var k = myItems.length - 1; k >= 0; k--) {

    $.write(myItems);

}

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