2 Replies Latest reply on May 8, 2016 8:21 AM by mirandajane

    Dialogue box results "not a number"


      Hello! I'm new to InDesign scripting (as of today) and am having difficulty with using dialogue box results in my script. The script I've put together creates calligraphy line guides down a page, and I got it working fine but then wanted to be able to specify the distances between the lines in a dialogue box rather than in the script, and it's now not working.


      I know that everything from line 43 downwards works if I remove the dialogue box and create the variables using parseInt() rather than pulling them in from the dialogue box, but as soon as I try to use the values from the dialogue box it comes up with error 30491 on line 60 that ascenderHeight is Not a Number (and so it presumably can't use it to calculate within geometricBounds). I've tried converting a test variable to an integer beneath line 43, but it's not making any difference. Originally I was using the measurementEditBox as in the InDesign Scripting Tutorial, but figured that the integer one would remove any excess baggage. If someone could let me know where I'm going wrong, I'd really appreciate it!


      var myDialog = app.dialogs.add({name: "Set line guide parameters",canCancel:true}) ;
      with (myDialog){
      //Add labels dialog column.
          staticTexts.add({staticLabel:"X-height to ascender (mm)"});
          staticTexts.add({staticLabel:"X-height (mm)"});
          staticTexts.add({staticLabel:"Descender height (mm)"});
          staticTexts.add({staticLabel:"Slant angle"});
      //Add entry dialog column
        //Create integer & angle entry fields.
          var ascenderHeightField = integerEditboxes.add({editValue:5}) ;
          var xHeightmmField = integerEditboxes.add({editValue:5}) ;
          var descenderHeightField = integerEditboxes.add({editValue:2}) ;
          var slantAngleField = angleEditboxes.add({editValue:-30}) ;
          //Display the dialog box.
          var myResult = myDialog.show() ;
          if (myResult == true) {
              //Get the values from the dialog box controls
              var ascenderHeight = ascenderHeightField;
              var xHeightmm = xHeightmmField;
              var descenderHeight = descenderHeightField;
              var slantAngle = slantAngleField;
              //Remove the dialog box from memory.
              buildGuide (ascenderHeight, xHeightmm, descenderHeight, slantAngle);
              myDialog.destroy() ;
      function buildGuide (ascenderHeight, xHeightmm, descenderHeight, slantAngle) {
      var ascenderHeight = parseInt(ascenderHeight);
      var lineHeight = (descenderHeight+xHeightmm+ascenderHeight);
      //Create lines for guide, specified distance apart on margin of 13mm (set this in variables once maths is working!)
      var capHeight = app.activeWindow.activePage.graphicLines.add() ;
      capHeight.geometricBounds = [13, 13, 13, 197] ;
      capHeight.strokeWeight = 2 ;
      var xHeight = app.activeWindow.activePage.graphicLines.add() ;
      xHeight.geometricBounds = [(13+ ascenderHeight), 13, (13+ ascenderHeight), 197] ;
      xHeight.strokeWeight = 1.5 ;
      var baseLine = app.activeWindow.activePage.graphicLines.add() ;
      baseLine.geometricBounds = [(13+ +ascenderHeight+ xHeightmm), 13, (13+ascenderHeight+xHeightmm), 197] ;
      baseLine.strokeWeight = 2 ;
      var Descender = app.activeWindow.activePage.graphicLines.add() ;
      Descender.geometricBounds = [(13+lineHeight), 13, (13+lineHeight), 197] ;
      Descender.strokeWeight = 1.5 ; 
      DistributeOptions.VERTICAL_SPACE, undefined, true, xHeightmm);*/ 
      //Create an x to mark the baseline and a diagonal at specified slant
      var lineMarker = app.activeWindow.activePage.textFrames.add() ;
      lineMarker.geometricBounds = [(13+ascenderHeight), 13,(13+lineHeight),17] ;
      lineMarker.contents = "X" ;
      var Diagonal = app.activeWindow.activePage.graphicLines.add() ;
      Diagonal.geometricBounds = [13, 30, (13+lineHeight+2), 30] ;
      Diagonal.strokeWeight = 1.5 ;
      Diagonal.absoluteRotationAngle = slantAngle ;
      //Group all created then duplicate down length of page
      var myGroup = new Array () ;
      myGroup.push(capHeight) ;
      myGroup.push(xHeight) ;
      myGroup.push(baseLine) ;
      myGroup.push(Descender) ;
      myGroup.push(lineMarker) ;
      myGroup.push(Diagonal) ;
      var myLineGroup = app.activeWindow.activePage.groups.add(myGroup);
      var myGroup2 = myLineGroup.duplicate(undefined,[0,lineHeight+2]);
      for (var i = lineHeight+2; i < (271-lineHeight); i=i+lineHeight+2){
          var dup_groups = app.activeWindow.activePage.groups.lastItem().duplicate(undefined, [0,i]) ;
          } ; 
      } ;
        • 1. Re: Dialogue box results "not a number"
          S Hopkins Adobe Community Professional

          Without getting into the entirety of your script, let's look at your dialog box:

          Take the code for your dialog box and copy it to a separate script.

          Now instead of calling build guide, replace that line with a test to see the values of your variables:

          [ascenderHeight, xHeightmm, descenderHeight, slantAngle];

          When you run the script, you will see where your problem is: The result is:

          Result: [object IntegerEditbox],[object IntegerEditbox],[object IntegerEditbox],[object AngleEditbox]

          You are getting a reference to the dialog box widgets, not the edit value.

          Add .editValue to each of your variable definitions so they read:

                  var ascenderHeight = ascenderHeightField.editValue; 

                  var xHeightmm = xHeightmmField.editValue; 

                  var descenderHeight = descenderHeightField.editValue; 

                  var slantAngle = slantAngleField.editValue;

          This should solve your problem.

          Bottom line: When you are having problems, isolate the code and evaluate the results.

          Hope this helps.

          1 person found this helpful
          • 2. Re: Dialogue box results "not a number"
            mirandajane Level 1

            Thank you for the quick reply! It's working perfectly now. I couldn't figure out how to see the values of my variables, so will bear that in mind in future (and try to start from the beginning and go through it more carefully!)