×
INTELLIGENT WORK FORUMS
FOR ENGINEERING PROFESSIONALS

Log In

Come Join Us!

Are you an
Engineering professional?
Join Eng-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Eng-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Jobs

Automatic removal of trailing zeros - expression to attribute function

Automatic removal of trailing zeros - expression to attribute function

Automatic removal of trailing zeros - expression to attribute function

(OP)
thread561-234303: Attributes and expressions

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 smile

RE: Automatic removal of trailing zeros - expression to attribute function

Use the "g" type in the format function.

CODE

format("%g", A_DIA) 

www.nxjournaling.com

RE: Automatic removal of trailing zeros - expression to attribute function

(OP)
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 smile

RE: Automatic removal of trailing zeros - expression to attribute function

(OP)
I thought it might help to add an example drawing of what I am trying to do (a very simple example at that) smile

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 smile

RE: Automatic removal of trailing zeros - expression to attribute function

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

RE: Automatic removal of trailing zeros - expression to attribute function

(OP)
Hi cowski, many thanks for your reply.

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

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?

RE: Automatic removal of trailing zeros - expression to attribute function

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

RE: Automatic removal of trailing zeros - expression to attribute function

(OP)
That is brilliant, thanks very much, works perfectly!!

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Eng-Tips Forums free from inappropriate posts.
The Eng-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Eng-Tips forums is a member-only feature.

Click Here to join Eng-Tips and talk with other members!


Resources