Skip to main content
dublove
Legend
Aug 23, 2025 6:08 PM UTC
Answered

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

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?

m1b
m1bCorrect answer
Community Expert
Aug 24, 2025 1:22 PM UTC

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

6 replies

m1b
Community Expert
Community Expert
Aug 23, 2025 8:15 PM UTC

Try adding this line near the start of your script. 

app.scriptPreferences.measurementUnit = MeasurementUnits.MILLIMETERS;

 

Translate
dublove
dubloveAuthor
Legend
Aug 24, 2025 2:51 AM UTC

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;

 

Translate
m1b
Community Expert
m1bCommunity ExpertCorrect answer
Community Expert
Aug 24, 2025 1:22 PM UTC

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

Translate