Skip to main content
dublove
Legend
August 23, 2025
Answered

I'm bummed about the uncertainty of the units (mm or point).

  • August 23, 2025
  • 1 reply
  • 363 views

I have set the scale ahead of time to convert the units to mm:

app.documents.item(0).viewPreferences.horizontalMeasurementUnits = MeasurementUnits.MILLIMETERS;
app.documents.item(0).viewPreferences.verticalMeasurementUnits = MeasurementUnits.MILLIMETERS;

I get a value 100 from the file name(100):

myWidth = Number(getFileName[1]);

Then assign the size in the object style:

w.transformAttributeOptions.transformAttrWidth = myWidth;

Sometimes it's correct, it's 100mm.

But sometimes the result j is 35.278 mm.
Then I know it treats it as 100 points.

How can I make sure that "w.transformAttributeOptions.transformAttrWidth" always gets 100mm?

Correct answer m1b

It depends on exactly what you are doing. Actually it can be complicated to work out exactly what behavior you will get for different things. My preference is to ALWAYS work in points. If I want another unit I multiply/divide as necessary.

 

For most scripts, this will suffice:

const mm = 2.834645;
app.scriptPreferences.measurementUnit = MeasurementUnits.PTS;
var myMarginExample = 22 * mm;
var myBoundsExample = [5 * mm, 5 * mm, 297 * mm, 210 * mm];

 

In my opinion this is very simple and avoids all the complication. There are other ways, too.

- Mark

1 reply

m1b
Community Expert
Community Expert
August 23, 2025

Try adding this line near the start of your script. 

app.scriptPreferences.measurementUnit = MeasurementUnits.MILLIMETERS;

 

dublove
dubloveAuthor
Legend
August 24, 2025

Hi m1b.

This sentence does not seem to have caused any changes.
It did not even change the units for the horizontal and vertical directions.

It is still  "point" there.

 

Use all three together?

Use all three together?
Now I want bugs, but there are no bugs. Only time will tell if it works.

app.scriptPreferences.measurementUnit = MeasurementUnits.MILLIMETERS;
app.documents.item(0).viewPreferences.horizontalMeasurementUnits = MeasurementUnits.MILLIMETERS;
app.documents.item(0).viewPreferences.verticalMeasurementUnits = MeasurementUnits.MILLIMETERS;

 

m1b
Community Expert
m1bCommunity ExpertCorrect answer
Community Expert
August 24, 2025

It depends on exactly what you are doing. Actually it can be complicated to work out exactly what behavior you will get for different things. My preference is to ALWAYS work in points. If I want another unit I multiply/divide as necessary.

 

For most scripts, this will suffice:

const mm = 2.834645;
app.scriptPreferences.measurementUnit = MeasurementUnits.PTS;
var myMarginExample = 22 * mm;
var myBoundsExample = [5 * mm, 5 * mm, 297 * mm, 210 * mm];

 

In my opinion this is very simple and avoids all the complication. There are other ways, too.

- Mark