Continue to Site

Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

  • Congratulations waross on being selected by the Eng-Tips community for having the most helpful posts in the forums last week. Way to Go!

Automatic removal of trailing zeros - expression to attribute function

Status
Not open for further replies.

201181

Mechanical
Apr 13, 2006
49
thread561-234303

Hi,

I am currently playing with the creation of attributes from expressions, so that they can be shown in a parts list on a 2D drawing. This is very new to me, just started playing with this function today.

I'm having no problems in creating the attributes from an expression using the following, which was explained very well in the thread linked above:

ug_setPartAttrValue("A",format("%f",A_DIA))

However, there is one small thing I would love to modify if possible. At the moment, the number is shown with 6 digits after the full stop (so for example, 17 shows as 17.000000). This is a bit annoying to show in the part table. I have found that in the above formula, one can add for example 0.2 ( ug_setPartAttrValue("A",format("%0.2f",A_DIA)) ) to limit the number of decimal places to 2, but is there any way to generate the attribute where it only creates the additional values after the zero, if they are present (so for example, 17.25 shows as 17.25, and not 17.250000, and 17 shows as 17 and not 17.000000)?

Any help would be most appreciated :)
 
Replies continue below

Recommended for you

Thanks very much cowski, worked brilliantly.

However, one other very small detail I need to correct now is that when I show the attributes/numbers on the parts list, they show with a full stiop instead of a comma for the number/decimal seperator. Is there a way to change this setting somehow?

In the parts list, my style settings for the attribute columns I have created is 'Text' and not 'Number. Also, when creating the part family, I have of course used the full stop in the excel sheet for the number seprator, but perhaps that is what causes the problem (even though I know a full stop is used in excel for number/decimal seperation).

And further help would be most appreciated :)
 
I thought it might help to add an example drawing of what I am trying to do (a very simple example at that) :)

In the parts list, what I am trying to set up is that the values shown for A and B use a comma as the decimal/fraction separator. I also want to automatically show the fraction part of the number ONLY if it exists (so 10.5 shows as 10,5 and 15.00 shows as 15).

Does anyone have a suggestion on how to change this? Can it be done some how in the attributes that are created by the expressions? Is there some other setting that I can change.

Any help would be most appreciated :)

 
 http://files.engineering.com/getfile.aspx?folder=45b34dfc-c2b4-4eb3-8990-8f39b5381f6b&file=model1_DRAWING.prt
I'd fix it in the expressions. You can replace characters in a string expression with the charReplace function. Your new function would look like:

Code:
charReplace(format("%g", your_expression), ".", ",")

www.nxjournaling.com
 
Hi cowski, many thanks for your reply.

Sorry but I don't understand how exactly to add the line to my existing expressions :)

Do I add to my expression/attribute 'A':

ug_setPartAttrValue("A",format("%g",A_DIAMETER))charReplace(format("%g", your_expression), ".", ",")

Or do I create a new expression?

 
Code:
ug_setPartAttrValue("A",charReplace(format("%g", A_DIAMETER), ".", ","))

When you upgrade to NX 8 or higher, it will be easier to associate expressions and attributes (the ug_setPartAttrValue function won't be necessary).

www.nxjournaling.com
 
That is brilliant, thanks very much, works perfectly!!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor