adobeextendscript

Is there a complete reference for ExtendScript's UnitValue object/prototype?


So I can't find, for the life of me, a clear breakdown of the components of ExtendScript's UnitValue object. Every source I found had something to do with Adobe, and didn't explain it. I'd really like to have a full reference on it, but if no one can find one, I need at least a few questions answered concerning it.

  1. First, what are its constructors?

I've seen UnitValue(10, 'px'), which makes sense, but I've also seen UnitValue(20, 20)

  1. Second, how can you convert from one unit to another?

  2. Third, how can you find its value and its unit?

I think I've seen uv.value, but nothing getting the units.

Lastly, as my tags indicate, this is for Adobe, of course, since I've never seen or heard of any other program that uses ExtendScript.


Solution

  • UnitValue is documented in the Adobe JavaScript Tools Guide.

    In particular, you create an object with v = new UnitValue(number, unit), where unit is a string value like in (inch), mm (millimeter), pt (point), px (pixel), etc.

    To convert a UnitValue to an actual number, use the as method, e.g. v.as("cm") to convert v into centimeters.