6 Replies Latest reply on Feb 15, 2017 9:32 PM by revathiv80720177

    Default Measurement setting using JavaScript

    revathiv80720177 Level 1

      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

        • 1. Re: Default Measurement setting using JavaScript
          [Jongware] Most Valuable Participant

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

           

          mySpecifiedhDefaultMeasurementUnits = myDocument.viewPreferences.horizontalMeasurementUnits
          mySpecifiedvDefaultMeasurementUnits = myDocument.viewPreferences.verticalMeasurementUnits
          
          1 person found this helpful
          • 2. Re: Default Measurement setting using JavaScript
            revathiv80720177 Level 1

            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

            • 3. Re: Default Measurement setting using JavaScript
              Laubender Adobe Community Professional & MVP

              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

              • 4. Re: Default Measurement setting using JavaScript
                revathiv80720177 Level 1

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

                  }

                }

                • 5. Re: Default Measurement setting using JavaScript
                  Laubender Adobe Community Professional & MVP

                  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

                  • 6. Re: Default Measurement setting using JavaScript
                    revathiv80720177 Level 1

                    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