Highlighted

Create a box in the lower right Corner in different sized document

Explorer ,
Aug 14, 2020

Copy link to clipboard

Copied

Hi, I found a simple script to create a box at (0, 0, 5 ,5)

 

 

var doc;
    // if there is no doc create one
    // if there is one - use it
    if(app.documents.length < 1){
        doc = app.documents.add();
    }else{
        doc = app.activeDocument;    
    }
    var rect = doc.pages.item(0).rectangles.add(); 
    
rect.geometricBounds = [0, 0, 5, 5];

 

I want to create two guide boxes, one in the upper left at 0,0 and one in the lower right corner (the size of the box does not matter).  

The lower right corner of this box snaps to the lower right corner of the document.

The trim size of the document will vary, so this is a challenge for me
My guess is take the doc.documentPreferences.pageWidth and doc.documentPreferences.pageHeight and minus the size of the box, then place it somehow, but I am not sure about the syntax. Any hint is appreciated. 


Adobe Community Professional
Correct answer by brianp311 | Adobe Community Professional

something like this should make it similar to the first box. 

var doc;
    // if there is no doc create one
    // if there is one - use it
    if(app.documents.length < 1){
        doc = app.documents.add();
    }else{
        doc = app.activeDocument;    
    }
    var rect = doc.pages.item(0).rectangles.add(); 
    var rect2 = doc.pages.item(0).rectangles.add(); 
    var ph = doc.documentPreferences.pageHeight;
    var pw = doc.documentPreferences.pageWidth;
    
rect.geometricBounds = [0, 0, 5, 5];
rect2.geometricBounds = [ph-5, pw-5, ph, pw];
TOPICS
Scripting

Views

81

Likes

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

Create a box in the lower right Corner in different sized document

Explorer ,
Aug 14, 2020

Copy link to clipboard

Copied

Hi, I found a simple script to create a box at (0, 0, 5 ,5)

 

 

var doc;
    // if there is no doc create one
    // if there is one - use it
    if(app.documents.length < 1){
        doc = app.documents.add();
    }else{
        doc = app.activeDocument;    
    }
    var rect = doc.pages.item(0).rectangles.add(); 
    
rect.geometricBounds = [0, 0, 5, 5];

 

I want to create two guide boxes, one in the upper left at 0,0 and one in the lower right corner (the size of the box does not matter).  

The lower right corner of this box snaps to the lower right corner of the document.

The trim size of the document will vary, so this is a challenge for me
My guess is take the doc.documentPreferences.pageWidth and doc.documentPreferences.pageHeight and minus the size of the box, then place it somehow, but I am not sure about the syntax. Any hint is appreciated. 


Adobe Community Professional
Correct answer by brianp311 | Adobe Community Professional

something like this should make it similar to the first box. 

var doc;
    // if there is no doc create one
    // if there is one - use it
    if(app.documents.length < 1){
        doc = app.documents.add();
    }else{
        doc = app.activeDocument;    
    }
    var rect = doc.pages.item(0).rectangles.add(); 
    var rect2 = doc.pages.item(0).rectangles.add(); 
    var ph = doc.documentPreferences.pageHeight;
    var pw = doc.documentPreferences.pageWidth;
    
rect.geometricBounds = [0, 0, 5, 5];
rect2.geometricBounds = [ph-5, pw-5, ph, pw];
TOPICS
Scripting

Views

82

Likes

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
Aug 14, 2020 0
Adobe Community Professional ,
Aug 14, 2020

Copy link to clipboard

Copied

something like this should make it similar to the first box. 

var doc;
    // if there is no doc create one
    // if there is one - use it
    if(app.documents.length < 1){
        doc = app.documents.add();
    }else{
        doc = app.activeDocument;    
    }
    var rect = doc.pages.item(0).rectangles.add(); 
    var rect2 = doc.pages.item(0).rectangles.add(); 
    var ph = doc.documentPreferences.pageHeight;
    var pw = doc.documentPreferences.pageWidth;
    
rect.geometricBounds = [0, 0, 5, 5];
rect2.geometricBounds = [ph-5, pw-5, ph, pw];

Likes

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
Reply
Loading...
Aug 14, 2020 0
Adobe Community Professional ,
Aug 14, 2020

Copy link to clipboard

Copied

Something like this:

 

var doc = app.activeDocument;
doc.viewPreferences.horizontalMeasurementUnits = MeasurementUnits.INCHES;
doc.viewPreferences.verticalMeasurementUnits = MeasurementUnits.INCHES;

var w = 2
var h = 2
var pw = doc.documentPreferences.pageWidth;
var ph = doc.documentPreferences.pageHeight;
var TLrect = doc.pages.item(0).rectangles.add();
var BRrect = doc.pages.item(0).rectangles.add();

TLrect.geometricBounds = [0, 0, h, w];
BRrect.geometricBounds = [ph-h, pw-w, ph, pw];

Likes

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
Reply
Loading...
Aug 14, 2020 0
Explorer ,
Aug 14, 2020

Copy link to clipboard

Copied

Thank you Brian and Rob, made my day again.
I will take both your code and dissect it for my purpose. 

Likes

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
Reply
Loading...
Aug 14, 2020 0
Adobe Community Professional ,
Aug 18, 2020

Copy link to clipboard

Copied

Hi together,

FWIW: You cannot assume that every page in a document is the same size.

 

You could get the bounds of e.g. page one with:

doc.pages[0].bounds

But if the page is transformed or the spread view is rotated you may get the wrong values.

 

Quoting Marc Autret: "there is one law that we learned from experience: DO NEVER TRUST page.bounds property."

It could get more complicated like you think. Read into the articles below at www.indiscripts.com:

 

From: "InDesign Scripting Forum Roundup #10"

Reframing Pages: a Dangerous Sport
Marc Autret, December 14, 2016
https://www.indiscripts.com/post/2016/12/indesign-scripting-forum-roundup-10#hd2sb2

 

Also:

From: "InDesign Scripting Forum Roundup #8"
Marc Autret, August 10, 2015

Notes on Resizing Individual Pages

https://www.indiscripts.com/post/2015/08/indesign-scripting-forum-roundup-8#hd1sb2

 

Finally look into this Opus Magnum to get an idea that nothing is easy with page sizes:

Coordinate Spaces & Transformations in InDesign — Chap.1-5
Marc Autret, June 30, 2018

https://www.indiscripts.com/post/2018/06/coordinate-spaces-and-transformations-5

 

Regards,
Uwe Laubender

( ACP )

Likes

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
Reply
Loading...
Aug 18, 2020 1