6 Replies Latest reply on Nov 7, 2016 5:00 AM by Obi-wan Kenobi

    Can't change Measurement Unit

    Gregorio Pellegrino

      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

        • 1. Re: Can't change Measurement Unit
          Obi-wan Kenobi Level 5

          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;
          

           

           

          (^/)

          • 2. Re: Can't change Measurement Unit
            Gregorio Pellegrino Level 1

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

             

            Gregorio

            • 3. Re: Can't change Measurement Unit
              Laubender Adobe Community Professional & MVP

              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

              1 person found this helpful
              • 4. Re: Can't change Measurement Unit
                Obi-wan Kenobi Level 5

                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;  
                

                 

                 

                (^/)

                • 5. Re: Can't change Measurement Unit
                  Laubender Adobe Community Professional & MVP

                  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

                  1 person found this helpful
                  • 6. Re: Can't change Measurement Unit
                    Obi-wan Kenobi Level 5

                    You're right! 

                     

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

                     

                    (^/)