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

Add layoutWindows[0].properties to document.properties by script

Participant ,
Jul 11, 2023 Jul 11, 2023

I would like to set different properties by script, like rulerOrigin, zoomPercentage and so on.
The properties I want to set are in different positions in the object model. 

 

If I set them individually for each node in the object model (does this make sense?), it works as expected:

var doc = app.documents[0];

doc.viewPreferences.properties = {
    rulerOrigin: RulerOrigin.PAGE_ORIGIN,
}

doc.layoutWindows[0].properties = {
    zoomPercentage: 100,
}

 

However, it would be more elegant, do put everything in doc.properties like so:

doc.properties = {
    viewPreferences: {
        rulerOrigin: RulerOrigin.PAGE_ORIGIN,
    }
}

 

Unfortunately, I can’t figure out, how to add doc.layoutWindows[0].

The following code doesn’t work: 

doc.properties = {
    viewPreferences: {
        showFrameEdges: true,
    },
    layoutWindows.item(0): {
        zoomPercentage: 100,
    }
}

 

Any idea, how this is done?

 

---

 

By the way: I’m not sure what layoutWindows[0] actually refers to. 
I guess it is meant to distinguish between multiple views of the same document. Am I right here?

 

Regards, Martin 

 

TOPICS
Scripting
586
Translate
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 , Jul 11, 2023 Jul 11, 2023

The document has a windows property, but that’s a collection not a single object with its own properties like viewPreferences. Even though the length of the windows collection is probably only 1, you will need to set the properties of the window separately. Same would be true of any document property that is a collection, e.g. stories.

Translate
Community Expert ,
Jul 11, 2023 Jul 11, 2023

Hi Martin, Windows are a property of the application not the document, so to set the zoom percentage try:

 

app.activeWindow.zoomPercentage = 100;

 

 

Translate
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
Participant ,
Jul 11, 2023 Jul 11, 2023

Thank you @rob day!
This works, but it’s not what I was trying to archive for two reasons: 

 

  • My question was mostly about aesthetics. The first snippet in my question works fine. However, I would find it more pleasing, to set all properties in one object (similar to the third snippet). I know, this doesen’t make any difference in the end, but I think it would also help me to get a better understanding of the possibilities in the syntax. 
  • The second reason is, I might integrate this into a larger script, that processes each document in a book. 
    To make it faster and more reliable, I’m considering opening each document in hidden mode. I guess, the hidden document window will not match app.activeWindow. – To be honest, I don’t know, if my way will work either, but I think it’s more likely. 
Translate
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 ,
Jul 11, 2023 Jul 11, 2023

The document has a windows property, but that’s a collection not a single object with its own properties like viewPreferences. Even though the length of the windows collection is probably only 1, you will need to set the properties of the window separately. Same would be true of any document property that is a collection, e.g. stories.

Translate
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
Participant ,
Jul 11, 2023 Jul 11, 2023

Thank you, @rob day
Just to be clear: So the structure I would prefer is simply not possible. Am I right?

 

Am I correct in assuming, that window[0] and window[1] are different views of the same document (as you would get via the Window → Arrange → New window for "filename.indd" menu)?

Translate
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 ,
Jul 11, 2023 Jul 11, 2023
LATEST

Right, I don’t think it would be possible with any property that is a collection. Here’s a list of document properties—Description will tell you if it is a collection:

 

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

 

Am I correct in assuming, that window[0] and window[1] are different views of the same document (as you would get via the Window → Arrange → New window for "filename.indd" menu)?

 

Yes. Create a new window for the active document and run this:

 

$.writeln(app.activeDocument.windows.length)
//returns 2

 

 

 

 

Translate
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