Continue to Site

Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

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

Having fun with Expressions... 1

Status
Not open for further replies.

JohnRBaker

Mechanical
Jun 1, 2006
35,672
Despite the important role that Expressions have come to play in capturing design intent in an NX part file, we sometimes overlook the little things that can be done with Expressions which can often lead to elegant solutions for some simple day-to-day needs or requirements. To that end, I'm starting this thread with the hope that those who have already discovered some of these "neat little tricks" will be willing to share them with the rest of us.

To start this off, I'll be postings a couple of recent things that I've come up with as well as perhaps some 'oldies' which may still prove useful for some people out there. My plan is to post example files in as old a version as possible, generally NX 3, unless the functionality is only available in a later version, this is so that as large a group of NX users as possible will be able to take advantage of these ideas.

Anyway, I hope this not only helps people who may find a need for these items, but also will get others to perhaps stop and think about how they could use Expressions to solve their special needs and then hopefully share with the rest of us what they've come up with.


John R. Baker, P.E.
Product 'Evangelist'
NX Design
Siemens PLM Software Inc.
Cypress, CA

To an Engineer, the glass is twice as big as it needs to be.
 
Rounding an Expression value to a specific decimal place...

As my first contribution, I was asked a week or so ago to help someone with rounding the arbitrary value of an Expression to a specific number of decimal places. The questions as it was put to me was:

Is there a simple way to "round" an Expression to the nearest 10th?

And the examples given were as follows:

How could I write an Expression which would "round" another Expression with a value of 1.24321 to 1.2000?

And could that same Expression "round" another Expression with a value of 1.25678 to 1.3000?

What I came up can be seen in the attached NX 3 file.

The formula which I used in the Expression was:

(floor((Input*10)+.5))/10

'Input' was the original unrounded expression. If you needed an Expression which would round to the 100th place, just change both 10's to 100's, or to the 1000th place, simply change them to 1000's and so on.

John R. Baker, P.E.
Product 'Evangelist'
NX Design
Siemens PLM Software Inc.
Cypress, CA

To an Engineer, the glass is twice as big as it needs to be.
 
Convert decimal degress to Degrees, Minutes and Seconds...

In this case the Question was how could an Angle Expression, which is always represented in decimal degrees, be converted so that a note could be added to a drawing which would show the value in 'Degrees, Minutes and Seconds' and of course update if the Expression changes?

My response was:

See the attached NX 3 file. The note shows the value of the expression titled 'Angle' (which is in decimal degrees) as degrees, minutes and seconds. To see how it works, open the Part Navigator and edit the value of the 'User Expressions' 'Angle'. To see how I did it, first double click the note to see how the note was formatted and then go to the Expression editor to see how the Expression titled 'Angle' was decomposed into 'Degrees', 'Minutes' and 'Seconds'.


John R. Baker, P.E.
Product 'Evangelist'
NX Design
Siemens PLM Software Inc.
Cypress, CA

To an Engineer, the glass is twice as big as it needs to be.
 
Sine Curve...

And of course there are always Law Curves and their use of Expressions.

In this case a simple Sine Curve where you can use Expressions to control the height of the curve (Amplitude), the wavelength (Length) and the number of cycles (Periods).


John R. Baker, P.E.
Product 'Evangelist'
NX Design
Siemens PLM Software Inc.
Cypress, CA

To an Engineer, the glass is twice as big as it needs to be.
 
I have an ejector pin model that could be a metric or inch size, standard or oversized. In all cases we want to drill the relief hole with a fractional drill, so I create the clearance value then round it off using the following expressions:

Code:
pin_dia 			1.000					   (any diameter)
clr_relief 		   .0625					(diametrical clearance)
relief_drill_dia1	pin_dia+clr_relief			(calculated relief diameter)
relief_drill_dia2	round(64/(1/Relief_drill_dia1)) (64ths drill numerator)
relief_drill_dia3	Relief_drill_dia2/64			(drill decimal diameter)

NX 5.0.3.2 MoldWizard
 
I was recently working on a design that incorporated Bal-Seal springs as a retaining feature. The question was how to model reasonably accurate representations of the springs. A quick internet search provide the formulas for a toroidal helix, which became the basis for a law curve. See part "toroidal helix".
But the Bal-Seal springs have a more oval cross section, so a little manipulation of the formulas resulted in "squished toroidal helix". Most of the expressions are self explanatory. The expression "p" controls the number of "threads". Change its value to a different whole number for an interesting effect.
 
 http://files.engineering.com/getfile.aspx?folder=6a9d09bb-5609-4bc4-ad0e-11e81f456c00&file=helix.zip
At a company that I was doing contract work for, I development an assembly where the base components were a motor and a pump. There were many other components besides that but those were the main ones. When one of these assemblies were ordered there are many pumps that can utilized, and well as many motors. The components that held these two together changed too.

In the base assembly I had all the pumps that could be used as well as a FEMA motor base model, which changed when the values of the motor changed. All the values that needed to be changed were entered via the visual editor.

By utilizing "suppression by expression", and by turning the components of the assembly on and off with expressions the assembly could be made to what the customer ordered.

suppression by expression >>>> edit > feature > suppress by expression > the last expression in the list will have either a "1" or a "0" to show that this feature is suppressed or not

suppress components in the assembly >>>> rmc component in ANT > suppress > controlled by expression > in the white box enter a "1" or a "0" to turn the component on or off > the expression in the list will be is one created with either a "1" or a "0"

The scale of the drawings changed (by using expressions) based on the size of the parts. double click on view > scale > expression

The model files and drawings were metric but some of the values that needed to be entered were inch based, but by setting the value of the expression to the proper unit that was not a problem.

I would have liked to base the design of the components on things like angular acceleration & velocity of the pump and motor, and stress and strain of the pump and motor, but I was told to keep it simpler. Those things are easily utilized with expressions.
 
I too needed to round values off typically to the nearest 1/8" or 1/16", and did it similar to the way John mentioned above ...
By multipling the number either by 8 (for nearest 8th) or by 16 (for the nearest 16th) then using either "floor" or "ceiling" to round that number to the nearest whole number, then dividing by the same number that you multiplied by (either an 8 or 16) to get the exact rounded value.
 
Really simple, but often over looked. When creating an equally spaced circular array, create a user defined expression with a name such as 'number_in_aray' and set its units to constant and enter a number in the formula before you create the array.

When you create the array from instance feature, in the number box enter 'number_in_array' and in the angle, enter '360/number_in_array'. This way, if you need to change the number in the array, the angle will automatically calculate itself to be equal for all instances. Simple yet effective.

Best regards

Simon (NX4.0.4.2 MP4 - TCEng 9.1.3.6.c)


Life shouldn't be measured by the number of breaths you take, but rather how many times it's taken away...
 
Using expressions to to create a "stepped" output:

We manufacture 6 sizes of a part with 3 different stem lengths. Sizes 1 & 2 have a 1.2 inch stem length, sizes 3 & 4 have a 1.5 inch stem length, and sizes 5 & 6 have a 1.8 inch stem length. To drive the stem lengths fron the size expression:

size = 1
stem_length =(ceil(size/2)*.3)+.9 = 1.2
size = 2
stem_length =(ceil(size/2)*.3)+.9 = 1.2

size = 3
stem_length =(ceil(size/2)*.3)+.9 = 1.5
size = 4
stem_length =(ceil(size/2)*.3)+.9 = 1.5

size = 5
stem_length =(ceil(size/2)*.3)+.9 = 1.8
size = 6
stem_length =(ceil(size/2)*.3)+.9 = 1.8
 
JCB,

Note that in NX 6 you can now create expression which can only be 'Integers' so this would work even better for your 'number_in_aray' case since this would prevent people from inadvertently entering a floating point number which could be misinterpreted.

John R. Baker, P.E.
Product 'Evangelist'
NX Design
Siemens PLM Software Inc.
Cypress, CA

To an Engineer, the glass is twice as big as it needs to be.
 
Weight Attribute

Ever have a need to capture the weight of part in something like an Attribute, and that it would update after editing the size of the model or if a change was made in the material assignment?

Attached is an example file (modeled in NX 4) where I use the Expression system to assign the value of the Mass of a solid body, using a Measurement Expression, to a Part Attribute using one of the 'function' Expressions, 'ug_setPartAttrValue'. Now we've got a text string that can be used in other places like a drafting note, in a parts lists and so on.

Anyway, take a look.

John R. Baker, P.E.
Product 'Evangelist'
NX Design
Siemens PLM Software Inc.
Cypress, CA

To an Engineer, the glass is twice as big as it needs to be.
 
John,
In your Weight Attribute example, how would you recommend truncating the resulting Attribute value for Mass to a certain number of digits?

ie:
7.865 kg
instead of
7.865064 kg

?
 
You cannot truncate it within the expression, it will need to be truncated at the application that it is being used ... is it being used in a note?
 
Yes, it's being used in a note, in this case.
 
You will need to go to the "relationships" tab in the text editor and click on expressions (first icon) - the pick that expression, the text will look something like this:

<X1.4@p1>

Where p1 is the expression and X1.4 is what controls how the number is displayed.
The "1" (after the X) signifies that the zero before the decimal is displayed (if the number is less than one) - if that number is a "0" then nothing will appear before the decimal point.
The "4" signifies how many digits passed the decimal point will be displayed.

so if p1=.31244733456
it will appear as 0.3124
 
Actually you CAN truncate within the Expression system as long as you know how ;-)

If you look at the attached updated 'Weight' example part and look at the expression titled 'WEIGHT_Attribute' you will see that it now reads:

ug_setPartAttrValue("WEIGHT",format("%0.2f kg",MASS))

What I added was an additional modifier to the 'formating' routine, in this case the '0.2', which tells the systems to truncate the result at 2 places (note however that this does NOT perform any ROUNDING of the result so be careful). Note that in the NX Expression system we have implemented a basic set of 'C-programming' style text string formatting tools and while this is not well documented in NX there are external references which can be helpful in using the various options. The external reference that I use is:


I'm sure that there are others out there, including of course any C-programming handbook or manual.

John R. Baker, P.E.
Product 'Evangelist'
NX Design
Siemens PLM Software Inc.
Cypress, CA

To an Engineer, the glass is twice as big as it needs to be.
 
John,
Thank you for the post; how would you recommend to ROUND, instead of truncate?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor