5 Replies Latest reply on Jun 20, 2011 12:51 PM by Harbs.

    Subtracting 5mm from pagewidth CS4

    TᴀW Adobe Community Professional & MVP

      Hi there.

      I've got the page width of a document:

       

      app.activeDocument.documentPreferences.pageWidth

       

      I would like to subtract 5mm from it.

       

      How do I do that?

       

      I can't set the ruler units, because this script is running in a ScripUI dialog box that's running while the user is able to work in InDesign (using #targetengine)

       

      Now, app.activeDocument.documentPreferences.pageWidth - "5mm" doesn't work.

       

      So it looks like I have to use a UnitValue object.

       

      But

       

      x = UnitValue (5, "mm")

      app.activeDocument.documentPreferences.pageWidth - x

       

      doesn't work either.

       

      So it looks like I need to convert the pageWidth into a UnitValue also.

       

      But how do I know what units are being used?

       

      The only option I can see is to go through all the possible MeasureUnits enumerations and compare.

       

      But is there a simpler way of doing all this?

       

      Many thanks,

      Ariel

        • 1. Re: Subtracting 5mm from pagewidth CS4
          Peter Kahrel Adobe Community Professional & MVP

          app.scriptPreferences.MeasurementUnits = MeasurementUnits.millimeters

          app.activeDocument.documentPreferences.pageWidth -= 5;

           

          Peter

          • 2. Re: Subtracting 5mm from pagewidth CS4
            Harbs. Level 6

            That .MeasurementUnits should have been .measurementUnits...

             

            Be very careful not to mess up existing scripts with this!!!

             

            I'd always wrap these changes in a try/catch/finally:

             

            try{
              var scriptUnits = app.scriptPreferences.measurementUnits;
              app.scriptPreferences.measurementUnits = MeasurementUnits.millimeters
              app.activeDocument.documentPreferences.pageWidth -= 5;
            }catch(err){}
            finally{
              app.scriptPreferences.measurementUnits = scriptUnits;
            }
            
            1 person found this helpful
            • 3. Re: Subtracting 5mm from pagewidth CS4
              Peter Kahrel Adobe Community Professional & MVP

              > That .MeasurementUnits should have been .measurementUnits...

               

              And so it should have been indeed.

               

              As to your other comment, I don't see the harm to other scripts in setting the measurement units: the units are set just for the script you're running. But, bother, does it maybe set the units for the session? Anyway, every script should set its own measurements.

               

              Peter

              1 person found this helpful
              • 4. Re: Subtracting 5mm from pagewidth CS4
                TᴀW Adobe Community Professional & MVP

                Thanks very much guys. I didn't know about scriptPreferences. Looks like

                that should do the trick!

                • 5. Re: Subtracting 5mm from pagewidth CS4
                  Harbs. Level 6

                  pkahrel wrote:

                   

                  Anyway, every script should set its own measurements.

                   

                  scriptPreferences.measurementUnits didn't exist prior to version 7 (I think). Legacy scripts all use viewPreferences.verticalMeasurementUnits and viewPreferences.horizontalMeasurementUnits. With scriptPreferences set to a different measurement unit, things will start to break in weird and unexpected ways.

                   

                  I don't know about you, but I have not updated all my scripts to take this into account...

                   

                  I'd always make sure that the value is returned to AutoEnum.AUTO_VALUE at all costs...

                   

                  Harbs