Gonda Posted May 7, 2017 Share Posted May 7, 2017 Hey All, So, I'm looking to retrieve some fields from a custom PIO object and then drawing them as text in the document. I've defined the parameters as dimensions so that when the units of the document changes, units of said fields in the OIP change and you case use standard entering of numbers with units. What I'm getting stuck on if formatting these values. Whether I use PParametr_name or GetRField() to obtain these values, theyre always returned as a real number. Is their either a different function that I should be using to return the values as VW displays them in the OIP (i.e. 3'4", 54mm, 7.6m, etc) or is there an inbuilt function to convert the reals to display based on the documents current primary/secondary unit info or is this a function that I am going to need to build? Cheers all, -gonda Quote Link to comment
MullinRJ Posted May 7, 2017 Share Posted May 7, 2017 Gonda, Have you tried Num2StrF()? The "F" is for FORMATTED. Description: Function Num2StrF converts a specified REAL value into a string. The numeric value will be converted and displayed in the current unit settings of the drawing. Raymond Quote Link to comment
Gonda Posted May 9, 2017 Author Share Posted May 9, 2017 Hey Raymond, Thanks for the info. This is basically what I'm looking for. I don't suppose there is a way to force it to print unit marks? I notice it does for Feet/Inches but seemingly it doesnt for metric units (i.e. mm, cm, m, km, etc) Cheers, -gonda Quote Link to comment
MullinRJ Posted May 9, 2017 Share Posted May 9, 2017 Well, Gonda, actually there is. ;-) Try this script: import vs # show how to turn the units suffix ON and OFF when using Num2StrF() CR = chr(13) # Carriage Return # main # vs.SetPref(163, True) # Show units S = vs.Num2StrF(3) vs.SetPref(163, False) # Hide units S = vs.Concat('With units: ', S, CR, 'Without units: ', vs.Num2StrF(3)) vs.AlrtDialog(S) HTH, Raymond Quote Link to comment
Gonda Posted May 13, 2017 Author Share Posted May 13, 2017 Hey Raymond, So, maybe I'm missing something, but when I pasted your script into a command plug-in, I get units with both outputs. Am I missing something? -gonda Quote Link to comment
MullinRJ Posted May 13, 2017 Share Posted May 13, 2017 Gonda, You only need one instance of the variable conversion. I showed two instances to illustrate with, and without, the units showing. Try: save163state = vs.GetPref(163) # save Show Units setting vs.SetPref(163, True) # Show Units ON S = vs.Num2StrF(your_VARIABLE_here) vs.SetPref(163, save163state) # restore Show Units setting If you are going to format a lot of values, you should turn the above snippet into a user defined function. HTH, Raymond Quote Link to comment
Recommended Posts
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.