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

Why isn't this script for drawing guides

Explorer ,
Jul 12, 2023 Jul 12, 2023

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?

TOPICS
Scripting
346
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 12, 2023 Jul 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 

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
Explorer ,
Jul 12, 2023 Jul 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.

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
LEGEND ,
Jul 12, 2023 Jul 12, 2023

Bounds - same as GeometricBounds for objects. 

 

[top, left, bottom, right]

[0,1,2,3]

 

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

If you know none of the pages have been resized, you could set the pw variable to the document’s documentPreferences pageWidth property, but the page itself doesn’t have a pageWidth property which is why your script throws an error. Getting the width from the .bounds property is just safer.

 

 

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