skip to Main Content

So, I searched through the documentation on AI CS6’s Scripting Reference (JavaScript / though actually ECMAScript), and I cannot find anything for managing units, or unit conversion. Is it missing?

Photoshop uses ECMAScript’s UnitValue object as a standard way for managing unit conversion, but I can’t find anything for Illustrator. Illustrator functions do not accept UnitValue instances – they only accept doubles, in the “points” unit.

How am I supposed to manage units in AI?

Or, if nothing else, how do I run conversions from a given unit to points?

p.s. Why is it points anyway? Is that script-default? My current default unit is inches.

2

Answers


  1. Answers to all your questions can be found in the Adobe Illustrator Scripting Guide (CS6 on the Adobe home page) in the Measurement units section. This section seem to remain unchanged for years.

    In particular,

    • “Illustrator uses points when communicating with your scripts
      regardless of the current ruler units
    • “If your script depends on […] units other than points, it must perform any unit conversions needed to represent your measurements as points.”
    • Precise conversion rules: 1 inch = 72 points, 1 inch = 2.54 cm, 1 pica = 12 points
    Login or Signup to reply.
  2. Try setting required units without conversion (replace PIXELS to probably POINTS):

        //at start of script:
        var originalUnit=preferences.rulerUnits;//alert(originalUnit);
        preferences.rulerUnits = Units.PIXELS;//alert(preferences.rulerUnits);
    
        //your main code here
    
        //at the end - restore units:
        preferences.rulerUnits = originalUnit;
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search