
1. Re: script to calculate the hypotenuse of a page and place a picture box
Marc Autret Apr 6, 2012 7:26 PM (in response to maxr2012)Hi maxrus,
It sounds so simple that no one has found it necessary to answer you! Indeed, we can easily retrieve the height and the width of a page, then calculate the diagonal, then create a square based on that length.
Anyway, let's try to make such routine work in any context, supporting any custom measurement units, rulers settings, rotated spreads and/or even scaled/skewed pages! To do so we need to avoid usual methods based on "geometric bounds". Interesting challenge!
Here is my attempt:
// Create a square based on the active page's diagonal length (10%) // =========================== function measureDiagonal(/*Page*/page) //  // Ret. the page's diagonal in pts (relative to the page CS) { var CS_INNER = CoordinateSpaces.innerCoordinates; var wh = page.resolve(AnchorPoint.bottomRightAnchor, CS_INNER)[0], w = wh[0], h = wh[1]; return Math.sqrt(w*w + h*h); // Pythagorean theorem } function createTopLeftCornerRectangle(/*Page*/page, /*num[2]*/wh) //  // wh: width and height of the rectangle in pts (relative to the page CS) { // Some const shortcuts //  var CS_SPREAD = CoordinateSpaces.spreadCoordinates, CS_INNER = CoordinateSpaces.innerCoordinates, RM_REPLACE = ResizeMethods.replacingCurrentDimensionsWith, AP_TOP_LEFT = AnchorPoint.topLeftAnchor; var spread = page.parent, // Create a rectangle (in the spread CSthe page CS is not relevant yet) //  rec = spread.rectangles.add({fillColor:'Black'}), // Page transformation values (relative to the spread) //  pageMxValues = page.transformValuesOf(CS_SPREAD)[0].matrixValues; // Normalize the rectangle in the spread // (the size does not matter here) //  rec.reframe(CS_SPREAD, [[0,0],[10,10]]); // Apply the page transfo to the rectangle // so that its inner space fits the page space //  rec.transform(CS_SPREAD, [[0,0], CS_SPREAD], pageMxValues); // Finally, resize the rec //  rec.resize(CS_INNER, AP_TOP_LEFT, RM_REPLACE, wh.concat(CS_INNER)); return rec; } var FACTOR = .1, // 10% win = app.layoutWindows.length && app.activeWindow, page = win && (win instanceof LayoutWindow) && win.activePage, size = page && page.isValid && FACTOR*measureDiagonal(page); size && createTopLeftCornerRectangle(page, [size,size]);
Not sure this is exactly what you were looking after.
Anyway...
@+
Marc

2. Re: script to calculate the hypotenuse of a page and place a picture box
John Hawkinson Apr 6, 2012 10:16 PM (in response to Marc Autret)Anyway, let's try to make such routine work in any context, supporting any custom measurement units, rulers settings, rotated spreads and/or even scaled/skewed pages! To do so we need to avoid usual methods based on "geometric bounds". Interesting challenge!
I think you might have scared him. Someone should demonstrate the easy way (I'll get to it...tomorrow?).

3. Re: script to calculate the hypotenuse of a page and place a picture box
maxr2012 Apr 9, 2012 7:34 PM (in response to Marc Autret)Thanks Marc,
This works great, it may be simple but I am still trying to get my head around it. I appreciate your quick response.
Cheers,
Max

4. Re: script to calculate the hypotenuse of a page and place a picture box
maxr2012 Apr 9, 2012 7:35 PM (in response to John Hawkinson)Hi John,
I would love to see your spin on this as well if you have the time.
Thanks,
Max