Skip to main content
Known Participant
July 12, 2023
Question

Why isn't this script for drawing guides

  • July 12, 2023
  • 1 reply
  • 337 views

Frequently I use nice neat guides for laying out objects and text in my InDesign document.

 

So, I thought I might create a simple script that would draw guides on my actively selected page of my InDesign file in certain proportions.

 

But it's not working! I don't know exactly why other than that I'm pretty sure I didn't call the active page width and height correctly. It's important that this script is generated on whatever the "active" page is, because it could be any page of a document, and different pages might use different proportions for laying things out, like 20% of the document's height at a time.


Here's part of a script for attempting to draw those guides

 

var docWidth = Number(app.activeWindow.activePage.pageWidth);
var docHeight = Number(app.activeWindow.activePage.pageHeight);
// guide test
for (var i = 0; i<6;++i){
        app.activeWindow.activePage.guides.add({location: docWidth*i*0.2, orientation: HorizontalOrVertical.VERTICAL});
}
myWindow.show();

 

This is the only component of my script that doesn't work. And it probably doesn't work because I didn't correctly call the actively selected page width and height, so how do I do that?

This topic has been closed for replies.

1 reply

rob day
Community Expert
Community Expert
July 12, 2023

Hi @dane13860245 , A page doesn’t have a pageWidth property. You can get the document’s default pagewidth with this:

 

doc.documentPreferences.pageWidth

 

But the activePage could have a custom size so get the width from the page.bounds property:

 

var doc = app.activeDocument;
//var pw = doc.documentPreferences.pageWidth
var ap = app.activeWindow.activePage;
var b = ap.bounds;
var pw = b[3]-b[1]
for (var i = 0; i<6;++i){
    ap.guides.add({location: pw*i*0.2, orientation: HorizontalOrVertical.VERTICAL});
}

probably better 

Known Participant
July 12, 2023

Thank you for the reply!


What is the b[3] - b[1]? The brackets indicate an array of some sort, but I'm just looking to be able to select any page at any time and apply the script.

Robert at ID-Tasker
Legend
July 12, 2023

Bounds - same as GeometricBounds for objects. 

 

[top, left, bottom, right]

[0,1,2,3]