2 Replies Latest reply on Jan 4, 2016 5:54 AM by Laubender

    Javascript help, script almost working but returns something weird

    scottr93836726

      Hi Scripters,

       

      I have an almost working Javascript Variable for inDesign that was kindly given to me,(see below) i know very very little about javascript and have almost got this working myself just need some help,

       

      The script returns the document size and unit of measurement to a variable but my aim was to get the unit of measurement to be abbreviated (ie; Millimeters to mm)

       

      It does work but it also returns a weird thing infront of mm (NaN).

      Screen Shot 2016-01-04 at 12.54.43.png

       

       

      function toTitleCase(s) {  
          return s.toLowerCase().replace(/\b\w/g, function () {return arguments[0].toUpperCase()});
      
      function getPageDimentions(page){  
          var width, height, bounds, units, abbr, decPlaces;  
          // function presumes that normal pages  
          // i.e. same vertical and horizontal and no page shape transformations  
          decPlaces = 3;  
          units = toTitleCase(page.parent.parent.viewPreferences.horizontalMeasurementUnits.toString()); // If you forgot to include the toTitleCase function then remove the method  
          abbr = UnitValue(units);
          bounds = page.bounds;  
          height = bounds[2] - bounds[0];  
          height = myRound(height, decPlaces);  
          width = bounds[3] - bounds[1];  
          width = myRound(width, decPlaces);     
          return height + " x " + width + " " + abbr 
      

       

       

      Any help would be greatly appreciated!!

       

       

      Scott