Skip to main content
Known Participant
March 8, 2008
Question

How to add pica values without converting to points

  • March 8, 2008
  • 5 replies
  • 1272 views
Hi,
i need a java script for InDesign CS2 immediately that should help me to add two pica values without any conversion.

i tried the following script
app.selection[0]=[app.selection[0].geometricBounds[0],app.selection[0].geometricBounds[0],app.selection[0].geometricBounds[1],app.selection[2]+"1p6".geometricBounds[3]]

consider app.selection[0].geometricBounds[2]=8p0;
my output is 8p6.001

thanks in advance........

Regards,
subha
This topic has been closed for replies.

5 replies

Adobe Expert
March 17, 2008
>how can i do that using ur code"

Nice one, jong.
Jongware
Adobe Expert
March 17, 2008
Nice one, Fred, but you left out the PointsToPica function.
And the 'add' operator.

As Dave, I'm mystified about the purpose of this. Why "1p6+2p"? It seems to imply a followup question, "It works but now I can't do "1c2-0.125in, how can i do that using ur code"
Inspiring
March 17, 2008
> Nice one, Fred, but you left out the PointsToPica function.
> And the 'add' operator.


I'm supposed to give it all away? ;)

Actually, he/she is probably better off keeping it in points and then
changing the preferences back to picas at the end of the script.
Inspiring
March 17, 2008
Why? Is that because you're taking input in this form from your users?

Writing such a script doesn't require any particular special knowledge of InDesign. It's just JavaScript working with strings and numbers. You might even find such a script on one of the many JavaScript centered sites out there on the internet.

Dave
Inspiring
March 17, 2008
How's this?

function PicasToPoints(picas){
var mySplit = picas.split(",")
var myAdigits = +mySplit[0];
var myPoints = myAdigits * 12;
var myBdigits = +mySplit[1];
var myTotal =myPoints + myBdigits;
return myTotal
}
Inspiring
March 17, 2008
Actually, you should change that to this:

function PicasToPoints(picas){
var mySplit = picas.split("p")
var myAdigits = +mySplit[0];
var myPoints = myAdigits * 12;
var myBdigits = +mySplit[1];
var myTotal =myPoints + myBdigits;
return myTotal
}
Known Participant
March 17, 2008
Hi thanks.......I need a script that will be able to add "1p6+2p" without any conversion to points..
Jongware
Adobe Expert
March 8, 2008
You can
i set
values to measurements because JS will recognize you're assigning a string type value to a numeric variable -- it will internally do something like toString, except this is probably toFloat. The function is written to parse and recalculate the string into the current measurement units.

This is what probably fails here; your string "1p6" is parsed with a default toNumber method, and the '6' is all that's returned (although I'd guess it would be the '1' ...)

Without the measurement specifier, it should work okay, with two caveats. It works in your current measurement only, and if this is pica's/points you have to recalculate a pica-point value into fractional values, i.e., "1p6" is 1.5.

There might be some posts here on converting units, but if you're unsure about the current measurement units, it's pretty easy to force one:

lastUnits = ViewPreference.horizontalMeasurementUnits;
ViewPreference.horizontalMeasurementUnits = MeasurementUnits.PICAS;
.. your stuff here ..
ViewPreference.horizontalMeasurementUnits = lastUnits;