2 Replies Latest reply on Jun 18, 2008 10:40 AM by CTC Imaging

    JS [CS2]: MeasurementEditBoxes

    CTC Imaging Level 1
      Seems there is an issue about the Unit Conversion in dialog...

      Can anyone check the following script? Specifically in the Dialog Area were the units seem to mix erroneously. I've intentional set the editUnits in some fields to see what was happening...
      FYI: 1) Regardless of what your Document Units is set to, W/O the editUnits specified, it shows "pt" as units which is WRONG!!!!
      2) Same issue when changing "app.scriptPreferences.version" to 5.0! Of course the duplicate method ERRORS because of the new transform matrix...

      ++++++++++++++++ Code +++++++++++
      #target indesign
      app.scriptPreferences.version = 4.0;

      //******************** BEGIN Main ********************

      if (app.documents.length == 0)
      {
      alert ("There are no open documents.");
      exit();
      }

      var myDoc = app.activeDocument;

      if (app.selection.length == 0)
      {
      alert ("You need to select at least 1 OBJECT!!!");
      exit();
      }

      //*** Store Current UNIT settings
      var myOrigin = myDoc.viewPreferences.rulerOrigin; //*** SAVE Ruler Original Setup.
      myDoc.viewPreferences.rulerOrigin = RulerOrigin.spreadOrigin; //*** Set Ruler to SPREAD to determine box location
      var DocHorzUnits = myDoc.viewPreferences.horizontalMeasurementUnits;
      myDoc.viewPreferences.horizontalMeasurementUnits = MeasurementUnits.inches;
      var DocVertUnits = myDoc.viewPreferences.verticalMeasurementUnits;
      myDoc.viewPreferences.verticalMeasurementUnits = MeasurementUnits.inches;

      var myITMS = app.selection;
      if ( myITMS.length == 1)
      {
      if (myITMS[0].constructor.name != "TextFrame")
      {
      myITMS[0]= myITMS[0].parent.textFrames[0];
      app.select(myITMS[0]);
      }
      }

      //*** Search TOTAL Width & Height of ALL Selection
      var myAPosX = myITMS[0].geometricBounds[1];
      var myAPosY = myITMS[0].geometricBounds[0];
      var myBPosX = myITMS[0].geometricBounds[3];
      var myBPosY = myITMS[0].geometricBounds[2];
      for (var cptITM = 1; cptITM < myITMS.length; cptITM++)
      {
      if (myITMS[cptITM].geometricBounds[1] < myAPosX)
      myAPosX = myITMS[cptITM].geometricBounds[1];
      if (myITMS[cptITM].geometricBounds[0] < myAPosY)
      myAPosY = myITMS[cptITM].geometricBounds[0];
      if (myITMS[cptITM].geometricBounds[3] > myBPosX)
      myBPosX = myITMS[cptITM].geometricBounds[3];
      if (myITMS[cptITM].geometricBounds[2] > myBPosY)
      myBPosY = myITMS[cptITM].geometricBounds[2];
      }
      var myXOffset = myBPosX - myAPosX;
      var myYOffset = myBPosY - myAPosY;
      var myXGap = 0;
      var myYGap = 0;

      if (myDoc.name.search(/GBC/i) > -1) //*** Business Cards ALWAYS Inches.
      {
      var myXCount = 2;
      var myYCount = 5;
      }
      else
      {
      var myXCount = 1;
      var myYCount = 1;
      }

      var myDialog = app.dialogs.add({name:"SUPER Step & Repeat Script", canCancel:true});
      with (myDialog)
      {
      //Add a dialog column.
      with (dialogColumns.add())
      {
      //Create a border panel.
      with (borderPanels.add())
      {
      staticTexts.add({staticLabel:"HORIZONTAL Count:"});
      var myXCountField = integerEditboxes.add({editValue:myXCount, minimumValue:0, maximumValue:9});
      }
      //Create a border panel.
      with (borderPanels.add())
      {
      staticTexts.add({staticLabel:"HORIZONTAL Gap:"});
      var myXGapField = measurementEditboxes.add({editUnits: MeasurementUnits.inches, editValue:myXGap});
      staticTexts.add({staticLabel:"HORIZONTAL Offset:"});
      var myXOffsetField = measurementEditboxes.add({editUnits: MeasurementUnits.inches, editValue:myXOffset});
      }
      //Create a border panel.
      with (borderPanels.add())
      {
      staticTexts.add({staticLabel:"VERTICAL Count:"});
      var myYCountField = integerEditboxes.add({editValue:myYCount, minimumValue:0, maximumValue:9});
      }
      //Create a border panel.
      with (borderPanels.add())
      {
      staticTexts.add({staticLabel:"VERTICAL Gap:"});
      var myYGapField = measurementEditboxes.add({editValue:myYGap});
      staticTexts.add({staticLabel:"VERTICAL Offset:"});
      var myYOffsetField = measurementEditboxes.add({editValue:myYOffset});
      }
      }
      }
      if (myDialog.show() == true)
      {
      v
        • 1. Re: JS [CS2]: MeasurementEditBoxes
          Level 1
          Hi Alexandre,

          Two things:

          1. Measurement edit boxes always return their value in points

          2. Measurement edit boxes do not take on the measurement system specified in your view preferences.

          You can change the edit units used to display values in the edit box to match the units in the document, but the edit value returned by the control will always be points. This is why I always set the measurement units to points while the dialog is up in the examples.

          You can use all of InDesign's measurement unit overrides in a measurement edit box, even if its edit units are set to points.

          Thanks,

          Ole
          • 2. Re: JS [CS2]: MeasurementEditBoxes
            CTC Imaging Level 1
            Thank you. I read some post that were erroneous. And I had a feeling about it when changing preferences to no avail...


            On Wed, Jun 18, 2008 at 2:20 PM, Olav Kvern < member@adobeforums.com> wrote:

            A new message was posted by Olav Kvern in


            InDesign Scripting --
              JS [CS2]: MeasurementEditBoxes

            Hi Alexandre,

            Two things:

            1. Measurement edit boxes always return their value in points

            2. Measurement edit boxes do not take on the measurement system specified in your view preferences.


            You can change the edit units used to display values in the edit box to match the units in the document, but the edit value returned by the control will always be points. This is why I always set the measurement units to points while the dialog is up in the examples.


            You can use all of InDesign's measurement unit overrides in a measurement edit box, even if its edit units are set to points.

            Thanks,

            Ole







            View/reply at JS [CS2]: MeasurementEditBoxes
            Replies by email are OK.
            Use the unsubscribe form to cancel your email subscription.