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

Valid page in script

Engaged ,
Sep 13, 2022 Sep 13, 2022

Copy link to clipboard

Copied

Longtime Photoshop scripter, first time INDD scripter.

 

I'm currently working on a page swaping script, though I'm stumped at the first hurdle.

Assuming I have a indd document open, with pages, why would a page be considered NOT valid?

 

var pages = app.activeDocument.pages;
var p = 0;
alert(pages.item("" + p).isValid);

 false

 

What have I missed or overlooked?

TOPICS
Scripting

Views

276

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 , Sep 13, 2022 Sep 13, 2022

pages.item takes an integer, not a string. It can also be shorthanded to: 

alert(pages[0].isValid);

 

Votes

Translate

Translate
Community Expert ,
Sep 13, 2022 Sep 13, 2022

Copy link to clipboard

Copied

pages.item takes an integer, not a string. It can also be shorthanded to: 

alert(pages[0].isValid);

 

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
Engaged ,
Sep 13, 2022 Sep 13, 2022

Copy link to clipboard

Copied

That's where the script was going wrong.  

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 14, 2022 Sep 14, 2022

Copy link to clipboard

Copied

LATEST

Hi @Ghoul Fool ,

the article to that script by Marc Autret you linked to is from the year 2009.

 

Never tested Marc's script there on a recent version of InDesign.

Marc's script was written for InDesign CS4, I think that was released in 2008.

Dramatic changes took place in the overall architecture of InDesign between CS4 and CS5 released in 2010.

 

InDesign CS4 had a totally different model of pages and spreads compared to CS5 where the first time in the history of InDesign a document could hold different page sizes. With CS4 this was not the case. Just to note one thing.

 

And yet another one: In InDesign CS4 you could return a collection of items with item("string") if the parent contained more than one with the same name. This option was gone with InDesign CS5 from about 2010. At least for most objects you can address with a string.

 

Regards,
Uwe Laubender
( Adobe Community Professional )

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
People's Champ ,
Sep 13, 2022 Sep 13, 2022

Copy link to clipboard

Copied

To answer this question: why would a page be considered NOT valid

isValid will return a boolean, true or false depending if the object reference is valid or not. For ex, you can reference a page that doesn't exist but you would get an error if you try to use this object. isValid is a property that let you check if the reference is accessible or not.

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 14, 2022 Sep 14, 2022

Copy link to clipboard

Copied

@brianp311 

Hi Brian -- Actually, pages.item() can be used with strings and integers. When used with an integer, you get the page's document offset, with a string, the string is the folio. So if you have a document with Arabic-style page numbering,

app.documents[0].pages.item('4').name >> 4
app.documents[0].pages.item(4).name >> 5

The good thing of using integers is that you can reference a page no matter is numbering style (Arabic, Roman, letter, etc.). And the good thing of using strings is that you can reference a page with a roman page number, or page numbers with an included section prefix.

 

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 14, 2022 Sep 14, 2022

Copy link to clipboard

Copied

Hi @Ghoul Fool ,

in case you were able to start a page section with a page named "0" your alert would return true.

As far as I know this is not possible. The numbering schemes do not allow this. A page name like "001" would be possible or even "0001" or "A" where you could fetch that page with all of the code lines below:

 

 

app.documents.item(0).pages.item("A")
app.documents.item(0).pages.itemByName("A")
app.documents[0].pages.item("A")
app.documents[0].pages.itemByName("A")
app.activeDocument.pages.item("A")
app.activeDocument.pages.itemByName("A")

 

 

 

WARNING:

A pages' name is perhaps not unique in a document if the document contains more than one page sections.

With item() and itemByName() you will not get a collection of pages named "A", but only the first instance.

 

See DOM documentation for document.section

https://www.indesignjs.de/extendscriptAPI/indesign-latest/#Section.html#d1e265407

 

Also consider that there is a huge difference between PhotoShop and InDesign when it comes to address the "active" document, the front most one. The good news: app.activeDocument is the same for PhotoShop and InDesign.

 

But if you are using iterators like item(0) or [0] there is a huge difference:

With PhotoShop app.documents[0] could be the active document. If it happens that the first document you opened in a given session is in front and active. In InDesign it absolutely always is the active document if all documents show a layout window. So the iterator numbers of item(i) or [i] of open documents could change if the user brings a different document to the front. Not so in PhotoShop.

 

Regards,
Uwe Laubender
( Adobe Community Professional )

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