Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

How to add pica values without converting to points

New Here ,
Mar 07, 2008 Mar 07, 2008
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
TOPICS
Scripting
1.3K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Mar 08, 2008 Mar 08, 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;
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Mar 16, 2008 Mar 16, 2008
Hi thanks.......I need a script that will be able to add "1p6+2p" without any conversion to points..
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Mar 17, 2008 Mar 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
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Enthusiast ,
Mar 17, 2008 Mar 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
}
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Enthusiast ,
Mar 17, 2008 Mar 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
}
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Mar 17, 2008 Mar 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"
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Enthusiast ,
Mar 17, 2008 Mar 17, 2008
LATEST
> 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.
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Mar 17, 2008 Mar 17, 2008
>how can i do that using ur code"

Nice one, jong.
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines