• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Can't change Measurement Unit

Community Beginner ,
Nov 07, 2016 Nov 07, 2016

Copy link to clipboard

Copied

Hi,

I'm developing a script. I would like to manage dimensions in millimeters; so I added at the top of the script:

app.scriptPreferences.measurementUnit = MeasurementUnits.MILLIMETERS;

But then I try to resize the page, and the dimensions are managed as points:

app.activeWindow.activePage.resize(CoordinateSpaces.INNER_COORDINATES, AnchorPoint.CENTER_ANCHOR, ResizeMethods.REPLACING_CURRENT_DIMENSIONS_WITH, [240, 100]);

Can you help me to understand where I'm wrong?

Gregorio

TOPICS
Scripting

Views

1.5K

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Expert , Nov 07, 2016 Nov 07, 2016

Hi Gregorio,

it is not working in any environment.

all x and y values for resize() are accepted as points only.
The same with reframe() and transform().

Recommended:

Indiscripts :: Coordinate Spaces & Transformations in InDesign — Chap.1-3

Indiscripts :: Coordinate Spaces & Transformations in InDesign — Chap.4 (Draft)

There is UnitValue you could use to do the necessary conversions.

var convertedValue = UnitValue(100,MeasurementUnits.MILLIMETERS).as(MeasurementUnits.POINTS);

Regards,
Uwe

Votes

Translate

Translate
LEGEND ,
Nov 07, 2016 Nov 07, 2016

Copy link to clipboard

Copied

Hi,

Personally, about MeasurementsUnits:

// ----------- Script beginning -----------

var myDoc = app.activeDocument;

var savedHorizontalMeasurementUnits = myDoc.viewPreferences.horizontalMeasurementUnits; 

var savedVerticalMeasurementUnits = myDoc.viewPreferences.verticalMeasurementUnits; 

myDoc.viewPreferences.horizontalMeasurementUnits = MeasurementUnits.MILLIMETERS; 

myDoc.viewPreferences.verticalMeasurementUnits = MeasurementUnits.MILLIMETERS;

………………

// ----------- Script end -----------

myDoc.viewPreferences.horizontalMeasurementUnits = savedHorizontalMeasurementUnits; 

myDoc.viewPreferences.verticalMeasurementUnits = savedVerticalMeasurementUnits;

(^/)

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Nov 07, 2016 Nov 07, 2016

Copy link to clipboard

Copied

It doesn't work in my environment... Can't understand!

Gregorio

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Nov 07, 2016 Nov 07, 2016

Copy link to clipboard

Copied

Hi Gregorio,

it is not working in any environment.

all x and y values for resize() are accepted as points only.
The same with reframe() and transform().

Recommended:

Indiscripts :: Coordinate Spaces & Transformations in InDesign — Chap.1-3

Indiscripts :: Coordinate Spaces & Transformations in InDesign — Chap.4 (Draft)

There is UnitValue you could use to do the necessary conversions.

var convertedValue = UnitValue(100,MeasurementUnits.MILLIMETERS).as(MeasurementUnits.POINTS);

Regards,
Uwe

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Nov 07, 2016 Nov 07, 2016

Copy link to clipboard

Copied

Hi Uwe,

Right! 

// ----------- Script beginning ----------- 

var myDoc = app.activeDocument; 

var savedHorizontalMeasurementUnits = myDoc.viewPreferences.horizontalMeasurementUnits;   

var savedVerticalMeasurementUnits = myDoc.viewPreferences.verticalMeasurementUnits;   

myDoc.viewPreferences.horizontalMeasurementUnits = MeasurementUnits.MILLIMETERS;   

myDoc.viewPreferences.verticalMeasurementUnits = MeasurementUnits.MILLIMETERS; 

var W = UnitValue("240mm").as('pt'); ; 

var L = UnitValue("100mm").as('pt'); 

 

app.activeWindow.activePage.resize(CoordinateSpaces.INNER_COORDINATES, AnchorPoint.CENTER_ANCHOR, ResizeMethods.REPLACING_CURRENT_DIMENSIONS_WITH, [W,L]); 

 

// ----------- Script end ----------- 

myDoc.viewPreferences.horizontalMeasurementUnits = savedHorizontalMeasurementUnits;   

myDoc.viewPreferences.verticalMeasurementUnits = savedVerticalMeasurementUnits; 

(^/)

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Nov 07, 2016 Nov 07, 2016

Copy link to clipboard

Copied

Hi Obi-wan,

in this case changing the viewPreferences is not necessary.

var W = UnitValue("240mm").as('pt');  

var L = UnitValue("100mm").as('pt');

app.activeWindow.activePage.

    resize

    (

        CoordinateSpaces.INNER_COORDINATES,

        AnchorPoint.CENTER_ANCHOR,

        ResizeMethods.REPLACING_CURRENT_DIMENSIONS_WITH,

        [W,L]

    );

Regards,
Uwe

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Nov 07, 2016 Nov 07, 2016

Copy link to clipboard

Copied

LATEST

You're right! 

Just a habit of systematical work in a "millimeters" context!

(^/)

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines