Thread View: adobe.scripting.indesign
3 messages
3 total messages
Started by Tom_Tomasko
Mon, 12 Jan 2009 00:48
[CS3][JS] How to turn negative number in array into string
Author: Tom_Tomasko
Date: Mon, 12 Jan 2009 00:48
Date: Mon, 12 Jan 2009 00:48
19 lines
1866 bytes
1866 bytes
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];
Re: [CS3][JS] How to turn negative number in array into string
Author: Tom_Tomasko
Date: Mon, 12 Jan 2009 02:18
Date: Mon, 12 Jan 2009 02:18
11 lines
1050 bytes
1050 bytes
Well, I think I have solved it. But I don't know why this solves it. I would think that in the above script all the variables would be numbers and not strings. But the data browser says they are strings. The solution is: var marginsLHand = [marginY1, Number(-marginX2).toFixed(4), marginY2, Number(-marginX1).toFixed(4)] If someone can explain why now all variables in the arrays are strings and not numbers, I'll be happy. Tom
Re: [CS3][JS] How to turn negative number in array into string
Author: Peter Kahrel
Date: Mon, 12 Jan 2009 12:29
Date: Mon, 12 Jan 2009 12:29
5 lines
735 bytes
735 bytes
Tom, marginPreferences returns numbers, but in JS, toFixed() converts numbers to strings. Peter
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads