Jump to content
Developer Wiki and Function Reference Links ×

PIO accounting for document units?


Recommended Posts

I wrote a really awesome plugin, but realized upon further testing that it (and I guess nothing else I've written) accounts for document units being anything other than inches or feet/inches.  Because I rarely draw any other way, I've never noticed it.  So, now I need to modify things to account for document units.  Is there a simpler way to do this outside of having a list of all possible units, and creating a multiplier variable which I then I have to multiply every dimension by?   

Link to comment

Take a look at the GetUnits function. One of the values returned is the UPI (Units Per Inch) of the current units of the drawing. You should be able to use this value as a multiplier / divisor to get the result you need.

 

Also take a look at Units function that will return a code for the current unit setting of the file (Inch/CM/MM/ etc.)

 

I am certain there are others who can provide more detail from real experience.

Link to comment
5 hours ago, Pat Stanford said:

Take a look at the GetUnits function. One of the values returned is the UPI (Units Per Inch) of the current units of the drawing. You should be able to use this value as a multiplier / divisor to get the result you need.

 

Also take a look at Units function that will return a code for the current unit setting of the file (Inch/CM/MM/ etc.)

 

I am certain there are others who can provide more detail from real experience.

 

Oh, perfect.  That will probably be what I need.  Going take me weeks to update all my plugins to work under different units settings.  Just something I never paid attention to.

 

42 minutes ago, MullinRJ said:

There’s also a VW Preference, 152? (I’m guessing because power is out and won’t be back until after midnight) that returns Units Per Inch. 


upi := GetPrefReal(152); 

 

You can scale dimensions by that value. Check the number, though. 


Raymond

 

Are you in the Atlanta area?  I have a bunch of friends who have lost power after a storm rolled through a few hours ago.

Link to comment
1 hour ago, SamIWas said:

Are you in the Atlanta area?  I have a bunch of friends who have lost power after a storm rolled through a few hours ago

 

No, North Texas. About 25 miles north of Dallas. No storms! Just heat. The good news is that it didn't take until midnight to come back on. Only about 90 minutes down. Next week is forecast to be up to 10°F hotter. If you don't hear from me, you'll know why.

 

Raymond

Link to comment

@SamIWas, 2 things...:

 

  1. Be sure to include appropriate units markers in your code for any hard-coded dimensions.  If you do that, VW will convert dimensions on-the-fly for you.
  2. As @MullinRJ recommended, you can use GetPrefReal(152) {Units Per Inch} to do things like converting given OIP dimensions to mm:

IF ValidNumStr (GetRfield(PIOHANDLE,PIONAME,'DIMENSIONVALUE'),DIMENSIONVARIABLE) THEN BEGIN END;
DIMENSIONinMM:= DIMENSIONVARIABLE*(25.4/GetPrefReal(152));

 

Link to comment

In adding to what @C. Andrew Dunning just posted. Look at the Num2StrF() function. It will format a dimension value to the current document units. So, if you work a problem in inches, but your document units are mm, then Message(Num2StrF(1")); will show '25.4 mm'. This may help your dialogs present document units, not calculation values.

ValidNumStr() works in the opposite direction, converting formatted string data and returning dimensioned numeric data. 

 

Bottom line, there are several ways to skin this cat. (Apologies to all cats for that last remark.)

 

Raymond

  • Like 1
Link to comment
5 hours ago, C. Andrew Dunning said:

@SamIWas, 2 things...:

 

  1. Be sure to include appropriate units markers in your code for any hard-coded dimensions.  If you do that, VW will convert dimensions on-the-fly for you.
  2. As @MullinRJ recommended, you can use GetPrefReal(152) {Units Per Inch} to do things like converting given OIP dimensions to mm:

IF ValidNumStr (GetRfield(PIOHANDLE,PIONAME,'DIMENSIONVALUE'),DIMENSIONVARIABLE) THEN BEGIN END;
DIMENSIONinMM:= DIMENSIONVARIABLE*(25.4/GetPrefReal(152));

 

Yes, this is what I need to go back and do. I didn't include the " after all of my dimensions, so they're all over the place.  I think the vast majority of the issues will be fixed with that.  From there, I'll just work on converting entries in the OIP to and from whatever units.

Link to comment
5 hours ago, MullinRJ said:

In adding to what @C. Andrew Dunning just posted. Look at the Num2StrF() function. It will format a dimension value to the current document units. So, if you work a problem in inches, but your document units are mm, then Message(Num2StrF(1")); will show '25.4 mm'. This may help your dialogs present document units, not calculation values.

ValidNumStr() works in the opposite direction, converting formatted string data and returning dimensioned numeric data. 

 

Bottom line, there are several ways to skin this cat. (Apologies to all cats for that last remark.)

 

Raymond

I use Num2StrF quite a bit, but since I've only really ever worked in feet/inches, I just thought it dealt with Feet (figuring that's what the F stood for).  Good to know that it works in other ways as well.  

Link to comment
31 minutes ago, SamIWas said:

Yes, this is what I need to go back and do. I didn't include the " after all of my dimensions, so they're all over the place.  I think the vast majority of the issues will be fixed with that.  From there, I'll just work on converting entries in the OIP to and from whatever units.

 

FWIW, I've paid LOTS of "stupid tax" by making units assumptions early on...

 

  • Like 1
Link to comment
  • Vectorworks, Inc Employee

The other thing to remember  is that in Vectorscript a lot of the unit information form the OIP is handled automatically so you don't always need to deal with units.

In the script if you are dealing with a dimension value you get into issues when adding. If you say y + 1, it will add 1 document unit to y, That could be 1", 1', 1m, 1mm depending on your document units. If you want to add 1 foot then be sure to include the unit mark y + 1' It's a lot easier than doing a lot of UPI conversions.

  • Like 1
Link to comment

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...