Skip to main content
Inspiring
July 11, 2023
Answered

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

  • July 11, 2023
  • 1 reply
  • 556 views

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 

 

This topic has been closed for replies.
Correct answer rob day

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.

1 reply

rob day
Community Expert
Community Expert
July 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;

 

 

C330 SAuthor
Inspiring
July 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. 
rob day
Community Expert
rob dayCommunity ExpertCorrect answer
Community Expert
July 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.