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

Default Measurement setting using JavaScript

New Here ,
Feb 15, 2017 Feb 15, 2017

Copy link to clipboard

Copied

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

TOPICS
Scripting

Views

3.2K

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 , Feb 15, 2017 Feb 15, 2017

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

...

Votes

Translate

Translate
Community Expert ,
Feb 15, 2017 Feb 15, 2017

Copy link to clipboard

Copied

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

mySpecifiedhDefaultMeasurementUnits = myDocument.viewPreferences.horizontalMeasurementUnits

mySpecifiedvDefaultMeasurementUnits = myDocument.viewPreferences.verticalMeasurementUnits

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
New Here ,
Feb 15, 2017 Feb 15, 2017

Copy link to clipboard

Copied

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

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 ,
Feb 15, 2017 Feb 15, 2017

Copy link to clipboard

Copied

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

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
New Here ,
Feb 15, 2017 Feb 15, 2017

Copy link to clipboard

Copied

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);

  }

}

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 ,
Feb 15, 2017 Feb 15, 2017

Copy link to clipboard

Copied

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

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
New Here ,
Feb 15, 2017 Feb 15, 2017

Copy link to clipboard

Copied

LATEST

Hi Uwe,

Thanks for your response.

Actually my process was to import a xml and then drag drop its elements.After importing the xml I am able to get my reference setting.I have a doubt.Is it possible to get the preference setting without any document open and have the same preference setting for the new imported xml?I am able to get the prefence setting only while drag drop the imported elements?

Regards,

Revathi V

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