2 Replies Latest reply on Jan 12, 2009 4:29 AM by Peter Kahrel

    [CS3][JS] How to turn negative number in array into string

    Tom Tomasko Level 1
      Hello,

      I have a script that compares the array of the geometric bounds of all text frames to the margins for a document (all pages having the same margins). Any frames that do not match the margins are flagged.

      In order to compare the array of text frame geometric bounds to two arrays of margins (because they are facing pages), I have to convert the numbers to strings.

      My problem is that in the following snippet of code that creates the two margin arrays, the negative of the variables become numbers again. This would not be too difficult to solve except that all the numbers have to be 4 decimal points before converted to strings.

      Thanks,
      Tom

      var myDoc = app.activeDocument;
      var marginY1 = myDoc.pages.item(0).marginPreferences.top.toFixed(4);
      var marginX1 = myDoc.pages.item(0).marginPreferences.left.toFixed(4);
      var marginY2 = (myDoc.documentPreferences.pageHeight - myDoc.pages.item(0).marginPreferences.bottom).toFixed(4);
      var marginX2 = (myDoc.documentPreferences.pageWidth - myDoc.pages.item(0).marginPreferences.right).toFixed(4);

      var marginsRHand = [marginY1, marginX1, marginY2, marginX2];
      var marginsLHand = [marginY1, -marginX2, marginY2, -marginX1];