as("px") - Usage Clarification - Unit conversion
Are there general guidelines on how to use .as("px") with a script? I noticed a bug when calling it through UnitValue vs directly. I had to include UnitValue for 0, presumably because it's a number?
My document is 5 inches x 5 inches @ 300 dpi.
alert("doc width: "+app.activeDocument.width) // returns "5 in"
alert("doc width as px: "+app.activeDocument.width.as("px")) // returns 1500
function asPX(measure) {
alert("func as px: "+measure.as("px"))
}
asPX(app.activeDocument.width) // returns 1500
function asPXUnit(measure) {
var measure = UnitValue(measure).as("px");
alert("func unitValue as px: "+measure)
}
asPXUnit(app.activeDocument.width) // returns 360
I guess best practice may be to test and convert any numbers to measurements.
Even nesting UnitValue(UnitValue().value,UnitValue().type).as("px"), returns 360.
