var margin = new UnitValue('1in');
var span = doc.documentPreferences.pageWidth - (2*margin);
I thought the above would work out ok, but it didn't. Here's output from the Javascript Console:
doc.documentPreferences.pageWidth
Result: 120
margin
Result: 1 in
2*margin
Result: 2 in
doc.documentPreferences.pageWidth - (2*margin)
Result: -118 in
doc.documentPreferences.pageWidth + (-2*margin)
Result: 118 in
![]()
I've had loads of problems using UnitValue, and have all but given up on that. I would guess the underlying problem is that JS doesn't really have a concept of "a number as measurement", so -- probably -- the result is a simple string. And you cannot do
var a = 2 * "1 in";
to get the output
$.writeln(a) -> "2 in"
Search this forum; I think I saw a workaround a while ago, using a small function to convert to and from different measurement units.
Sounds as a very serious bug!
It all seems as if UnitValue reverses the subtraction operands when the first term is a Number:
// tested in ID CS4 and CS5
var r = Number(10) - UnitValue(0,'in');
alert(r); // => -10 in
alert(r.__class__); // => UnitValue
alert(r.value); // => -10
alert(r.type); // => 'in'
Interestingly, we also get:
// tested in ID CS4 and CS5
alert( 10 - UnitValue() ); // => UnitValue -10.000000
alert( -10 - UnitValue() ); // => UnitValue 10.000000
Crazy!
Thanks for pointing that out, linx-eric.
@+
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).