Jump to content

Pretty Print Formatting


Recommended Posts

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

Link to comment

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

Link to comment

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

Link to comment

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

Link to comment

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

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...