Skip to main content
revathiv80720177
Known Participant
February 15, 2017
Answered

Default Measurement setting using JavaScript

  • February 15, 2017
  • 1 reply
  • 4054 views

In indesign , to set the measurements to particular format,for example to inches,  I use the script

myDocument.viewPreferences.horizontalMeasurementUnits = MeasurementUnits.INCHES;

myDocument.viewPreferences.verticalMeasurementUnits = MeasurementUnits.INCHES;

But I now want to get the default measurement units that I have specified in InDesign Preference setting.Is it possible?How can I get this?

Thanks and Regards,

Revathi

This topic has been closed for replies.
Correct answer Laubender

Hi Uwe,

I have got the values before importing the xml and have done all the thingsin one script.

Below I have mentioned my script

main();

with (myDocument.viewPreferences)

{

    var myOldXUnits = myDocument.viewPreferences.horizontalMeasurementUnits;

    var myOldYUnits = myDocument.viewPreferences.verticalMeasurementUnits;

}//Here tried to get indesign preference values but only getting it  always as inches.

//Import xml

function ImportXML(){

if(importOption=="FlOWINTOTEMPLATE")

{

  var docPath = app.scriptArgs.get("templateFilePath");

  myDocument = app.open(File(docPath),true);

  if(myDocument!=null)

  {

  var rootXMLElement = myDocument.xmlElements.item(0);

  ClearProductFamilies(rootXMLElement);

  }

}


The structure could be something like that:

main()

function main()

{

    var myDocument = app.documents[0];

  

    var myOldXUnits = myDocument.viewPreferences.horizontalMeasurementUnits;

    var myOldYUnits = myDocument.viewPreferences.verticalMeasurementUnits;

  

    ImportXML();

  

    myDocument.viewPreferences.horizontalMeasurementUnits = myOldXUnits;

    myDocument.viewPreferences.verticalMeasurementUnits = myOldYUnits;

    function ImportXML()

    {

        // Do something reasonable.

        // JUST AN EXAMPLE FOR SOMETHING NOT REASONABLE:

      

        myDocument.viewPreferences.horizontalMeasurementUnits = MeasurementUnits.POINTS;

        myDocument.viewPreferences.verticalMeasurementUnits = MeasurementUnits.INCHES;

      

        alert

        (

            "Measurement Units horizontal / vertical"+"\r"+

            myDocument.viewPreferences.horizontalMeasurementUnits.toString()+"\r"+

            myDocument.viewPreferences.verticalMeasurementUnits.toString()

        );

      

        return

      

    };

}

Regards,
Uwe

1 reply

Jongware
Community Expert
Community Expert
February 15, 2017

The measurement units properties are read/write, so to get them just read:

mySpecifiedhDefaultMeasurementUnits = myDocument.viewPreferences.horizontalMeasurementUnits

mySpecifiedvDefaultMeasurementUnits = myDocument.viewPreferences.verticalMeasurementUnits

revathiv80720177
Known Participant
February 15, 2017

Hi Jongware,

Thank you for your quick response.

I set my InDesign measurement setting to mm and tried to import xml using javascript.But after impporting the xml my measurement unit changes to inches.I used the script specified by you.But couldn't retain the setting.Could you help?

Regards,

Revathi V

Community Expert
February 15, 2017

Hi Revathi,

you are doing the import of XML by script.

So get the values before doing the part with the XML and after that restore the values.

Do all that in the same script.

If you want to do your XML import with a separate script and you have access to the source code, then you have at least two options:

1. Run all three scripts with the same #targetengine directive.

A. Script 1: Get the values

B. Script 2: Do the XML thing

C. Script 3: Restore the values

All three scripts share the same variables and their values.

2. Use a label to store information

A. Script 1: Store the values with a label using methods insertLabel( "KeyString" , "ValueString" ) with e.g. the document.

B. Script 2: Do the XML thing

C. Script 3: Retrieve the old values from the label using extractLabel("KeyString"), that will return the contents of the label and eval("ReturnedString") from the document.

If you have no access to the source code of the XML script you still can do option 2.

Regards,
Uwe