6 Replies Latest reply on Apr 17, 2009 11:32 AM by Peter Kahrel

# Unit conversion

Is there an easy way to convert measurement units?

For instance I need to calculate the depth of a paragraph with a rule below it and the .RuleBelowLineWeight always returns points, which makes sense. But, all the calculations I'm doing in this particular script can be done in whatever units are currently active except for that .RuleBelowLineWeight value.

I'm currently changing the units to points to do all the calculations so it works with the .RuleBelowLineWeight value (seemed easiest) but it would be cool to have a way, or even a routine, to be able to pass the value and a unit and receive back a value in the unit I need.

Thanks!

Ken

• ###### 1. Re: Unit conversion

Ignore that whole first post I wrote. I didn't notice this was the Scripting sub-forum!

Depending on the area you are in, I have been able to get ID to do some conversion for me in AppleScript at least. Eg. width = "5p" will convert automatically to 60pts. I don't know if that works for the rules below or not though.

• ###### 2. Re: Unit conversion

Thanks, your first post gave me just that idea. I'll investigate a bit. I can write a routine to do exactally what I need and maybe that will be the best thing to do, I was just hoping for a cheat!

Thanks again,

Ken

• ###### 3. Re: Unit conversion

In JS you can use UnitValue. To convert millimeters to points, for example, use this:

UnitValue (5, 'mm').as ('pt')

The Object Model Viewer in CS4 gives more details.

Peter

• ###### 4. Re: Unit conversion

Good to know. I was just testing in JS, and just entering the value with units definitely works in some areas too.

app.activeDocument.documentPreferences.pageHeight = '720pt' is valid, for example.

• ###### 5. Re: Unit conversion

Thanks Pete, that's cool. Currently, though, I'm working in VBA, for which the object model doesn't appear to have a counterpart to UnitValue, not that I can find anyway. Lord knows I've been terrible at finding such things in the past!

Thanks again,

Ken

• ###### 6. Re: Unit conversion

Yeah, I've used that before, the trouble comes when you want to add various values.

Thanks,

Ken