Hi all,
Mac OS X 10.5.6/InDesign 6.01/JavaScript or AppleScript
When the spreads is rotated view, the page item's visibleBounds (and geometricBounds) is change.
How to method of examining whether the spreads rotated?
example:
my_spread = app.layoutWindows[0].activeSpread;
my_spread.rotate; //of course, error
//I wish like this , =>ROTATE_CCW Value: 1987736183
Thanks.
--
You can work out whether or not a spread is rotated by looking at
the page.bounds,
Oh, no!!!
![]()
I never realized that bounds were effected by page rotation. That's
bad, bad, bad!!!
This will mess up just about every script under the sun which deals
with bounds of any kind!
We need this changed...
It is just a rotated view after all, so why are the bounds effected?
Harbs
Thank you!
This is good method for only check.
I can stop myscript, if the spreads is rotate.
function spread_angle(page_obj) {
//The bounds of the Page, in the format [y1, x1, y2, x2].
var my_page_bounds = page_obj.bounds;
var y1 = my_page_bounds[0];
var x1 = my_page_bounds[1];
var y2 = my_page_bounds[2];
var x2 = my_page_bounds[3];
if((y1 == 0) && (x1 == 0)) {
return 0;
} else if ((y1 == 0) && (x2 == 0)) {
return 90;
} else if ((y2 == 0) && (x2 == 0)) {
return 180;
} else if ((x1 == 0) && (y2 == 0)) {
return 270;
}
}
var my_page = app.layoutWindows[0].activePage;
spread_angle(my_page);
>We need this changed...
I agreed too...
Again, thanks.
--
Just make sure the zeroPoint is set to Re: How to check the rotated spreads?, and the rulerOrigin is
page. I like to work with spread origin, in which case, you'd pass a
spread instead of a page...
Harbs
Thank you, Harbs.
Oops!
I had overlooked some matters. It is as you say.
This is OK?
function spread_angle(spread_obj) {
var my_document = app.activeDocument;
var my_old_ruler_origin = false;//
if (my_document.viewPreferences.rulerOrigin != 1380143215) {//not page
my_old_ruler_origin = my_document.viewPreferences.rulerOrigin;//current setting
my_document.viewPreferences.rulerOrigin = 1380143215;//change
}
var my_old_zeroPoint = false;
if (my_document.zeroPoint != [0, 0]) {
my_old_zeroPoint = my_document.zeroPoint;
my_document.zeroPoint = [0,0];
}
var my_page = spread_obj.pages[0];
var my_page_bounds = my_page.bounds;
var my_angle = -1;
if((my_page_bounds[0] == 0) && (my_page_bounds[1] == 0)) {
my_angle = 0;
} else if ((my_page_bounds[0] == 0) && (my_page_bounds[3] == 0)) {
my_angle = 90;
} else if ((my_page_bounds[2] == 0) && (my_page_bounds[3] == 0)) {
my_angle = 180;
} else if ((my_page_bounds[1] == 0) && (my_page_bounds[2] == 0)) {
my_angle = 270;
}
if(my_old_ruler_origin) {my_document.viewPreferences.rulerOrigin = my_old_ruler_origin}
if(my_old_zeroPoint) {my_document.zeroPoint = my_old_zeroPoint}
return my_angle
}
var my_spread = app.layoutWindows[0].activeSpread;
spread_angle(my_spread);
--
seuzo
Hi Seuzo,
Very well done.
I took your code and cleaned it up the way I would have done it (I don't think you gain very much -- if anything, from all those "if"s). I also restructured the function to accept both Page and Spread objects. Assuming that the document is the active one is not a safe asumption. I changed that as well...
function GetSpreadRotation(pageOrSpread) {//accepts a Page, Spread, or MasterSpread
var doc = pageOrSpread.parent;// the doc will be either the parent, or the parent's parent...
if(pageOrSpread instanceof Page){doc=doc.parent}
//if(!(doc instanceof Document)){return null}// uncomment this to error check for the wrong type of pageOrSpread...
var origRulerOrigin = doc.viewPreferences.rulerOrigin;
var origZP = doc.zeroPoint;
doc.zeroPoint=[0,0];
doc.viewPreferences.rulerOrigin = RulerOrigin.PAGE_ORIGIN;
var page = pageOrSpread;
if (!(page instanceof Page)){// it must be a Spread or MasterSpread
page=pageOrSpread.pages[0];
}
var pageBounds = page.bounds;
var retAngle = 0;
if(pageBounds[0] == 0 && pageBounds[1] == 0) {
retAngle = 0;
} else if (pageBounds[0] == 0 && pageBounds[3] == 0) {
retAngle = 90;
} else if (pageBounds[2] == 0 && pageBounds[3] == 0) {
retAngle = 180;
} else if (pageBounds[1] == 0 && pageBounds[2] == 0) {
retAngle = 270;
}
doc.viewPreferences.rulerOrigin = origRulerOrigin;
doc.zeroPoint = origZP;
return retAngle;
}
var doc=app.documents[0];
var spread = doc.spreads[0];
spread_angle = GetSpreadRotation(spread);
alert("Spread Angle: " + spread_angle);
var page = doc.pages[0];
spread_angle = GetSpreadRotation(page);
alert("Page Angle: " + spread_angle);
var masterSpread = doc.masterSpreads[0];
spread_angle = GetSpreadRotation(masterSpread);
alert("Master Spread Angle: " + spread_angle);
function getSpreadRotation(/*Page|Spread|MasterSpread*/ps)
// ---------------------------------------------------------
// 0 => NORMAL , -90 => CW, +90 => CCW, 180 => REVERSED
{
return ps.
transformValuesOf(CoordinateSpaces.pasteboardCoordinates)[0].
counterclockwiseRotationAngle;
}
// Test
// ---
var mySpread = app.activeDocument.spreads[0];
alert( getSpreadRotation(mySpread) );
@+
Marc
North America
Europe, Middle East and Africa
Asia Pacific
Copyright © 2012 Adobe Systems Incorporated. All rights reserved.
Use of this website signifies your agreement to the Terms of Use and Online Privacy Policy (updated 07-14-2009).