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!

NX CONDITIONAL LOGIC STATEMENTS 5

Status
Not open for further replies.

rmarkham

Automotive
Nov 14, 2014
12
I am trying to write a conditional statement to control bushing clearance size, based on bushing OD.
There are difference clearance requirements for different diameter bushings.
NX 8.5 if that makes a difference.
Below is the information:

Range_____clearance
0-3mm____0.010mm____________1
3-6_______0.012_______________2
6-10______0.015_______________3
10-18_____0.018_______________4
18-30_____0.021_______________5
30-50_____0.025____TOLERANCE_6
50-80_____0.030_______________7
80-120____0.035_______________8


expressions are set at:
"BUSHING_OD"____30
"TOLERANCE_6"___0.025

So this is what I have so far which works as intended:
"BUSHING_CLEAR" = IF((BUSHING_OD>=30)&&(BUSHING_OD<50))THEN(TOLERANCE_6)
"BUSHING_CLEAR" = IF((BUSHING_OD>=50)&&(BUSHING_OD<80))THEN(TOLERANCE_7)
"BUSHING_CLEAR" = ETC.....

What I want to do is CONNECT multiple if/then/else statements under the expression "BUSHING_CLEAR"
How do I connect multiple conditional statements together, is it possible?
Everything above 120mm should be set at TOLERANCE_8



 
Replies continue below

Recommended for you

I tried doing this below, which did not work, syntax error.
"BUSHING_CLEAR" = IF((BUSHING_OD>=30)&&(BUSHING_OD<50))THEN(TOLERANCE_6)ELSE(IF(XXXXXXXX)THEN(xxxxxxxxx)ELSE(0))

That this is the idea I am trying to do, if it's possible
 
IF((BUSHING_OD>=30)&&(BUSHING_OD<50))THEN(TOLERANCE_6) else if ((BUSHING_OD>=50)&&(BUSHING_OD<80))THEN(TOLERANCE_7) etc ending with a final else for the last condition.

Is that what you're looking for?

NX9.0.3.4 MP1/Windos 7 Service Pack 1
 
oops....just a little messed up

IF((BUSHING_OD>=30)&&(BUSHING_OD<50))TOLERANCE_6 else if ((BUSHING_OD>=50)&&(BUSHING_OD<80))TOLERANCE_7 else TOLERANCE_8

NX9.0.3.4 MP1/Windos 7 Service Pack 1
 
Yes! That worked, I could not get it formatted correctly to work thank you!
 
Here it is working in all it's glory!

if((BUSHING_OD_IPE>=0)&&(BUSHING_OD_IPE<3))H7_BORE_TOLERANCE_1 else if((BUSHING_OD_IPE>=3)&&(BUSHING_OD_IPE<6))H7_BORE_TOLERANCE_2 else if((BUSHING_OD_IPE>=6)&&(BUSHING_OD_IPE<10))H7_BORE_TOLERANCE_3 else if((BUSHING_OD_IPE>=10)&&(BUSHING_OD_IPE<18))H7_BORE_TOLERANCE_4 else if((BUSHING_OD_IPE>=18)&&(BUSHING_OD_IPE<30))H7_BORE_TOLERANCE_5 else if((BUSHING_OD_IPE>=30)&&(BUSHING_OD_IPE<50))H7_BORE_TOLERANCE_6 else if((BUSHING_OD_IPE>=50)&&(BUSHING_OD_IPE<80))H7_BORE_TOLERANCE_7 else if((BUSHING_OD_IPE>=80)&&(BUSHING_OD_IPE<120))H7_BORE_TOLERANCE_8 else H7_BORE_TOLERANCE_8
 
Shorter version:
Code:
IF(BUSHING_OD>=80)(TOLERANCE_8)ELSE(IF(BUSHING_OD>=50)(TOLERANCE_7)ELSE(IF(BUSHING_OD>=30)(TOLERANCE_6)ELSE(IF(BUSHING_OD>=18)(TOLERANCE_5)ELSE(IF(BUSHING_OD>=10)(TOLERANCE_4)ELSE(IF(BUSHING_OD>=6)(TOLERANCE_3)ELSE(IF(BUSHING_OD>=3)(TOLERANCE_2)ELSE(TOLERANCE_1)))))))

www.nxjournaling.com
 
I like the version from cowski better for your requirements. The "else if" works well for odd comparisons that don't go in such a linear manner. Great timing though, the shorter version will work well for a few expressions I'm writing right now.

NX9.0.3.4 MP1/Windos 7 Service Pack 1
 
Awesome, I agree that shorter version is better. Learning everyday [smile]
 
There might be some additional refinement that could be done using 'List Expressions' and the 'nth' function.

Here are a couple of threads where the 'List Expression' is discussed and examples provided:






John R. Baker, P.E. (ret)
EX-Product 'Evangelist'
Irvine, CA
Siemens PLM:
UG/NX Museum:

The secret of life is not finding someone to live with
It's finding someone you can't live without
 
So, just for fun, and since John mentioned the "list" and "nth" functions, here's the solution to which he's alluding:

You can actually put all of these range values and tolerance values in a single list expression, like this:

Code:
{
{0, 3, 0.01}, 
{3, 6, 0.012}, 
{6, 10, 0.015}, 
{10, 18, 0.018}, 
{18, 30, 0.021}, 
{30, 50, 0.025}, 
{50, 80, 0.03}, 
{80, 120, 0.035}
}

Prior to NX 11, this is most easily done using the little "Extended Text Entry" button on the right end of the Formula field:

URL]


...and in NX 11, we'll get you away from the curly brackets and commas with the ability to directly edit the data in this list expression like a table:

URL]


And yes, I just copied-and-pasted that data into the expression edit dialog directly from Excel. We think you're going to like being able to do that. :)

But anyway, the other trick is crafting an expression to "look up" the right tolerance value from the table. And that's where the concept of lopping through the list comes in really handy. Here's the formula for a BUSHING_CLEAR expression:

Code:
loop {
for $set in tol_data;
If ( ( BUSHING_OD > nth(1,$set) ) && ( BUSHING_OD <= nth(2,$set) ) ) Return nth(3,$set);
Return is 999;
}

Again, this is most easily done in the "Extended Text Entry" mode, rather than trying to set it all up in a single line. The "Extended Text Entry" will preserve any formatting you introduce, and make it much easier to come back and edit this later.

Now... for the interested student, this is a case where it's handy to have the Knowledge Fusion language lurking underneath NX Expressions.

1. The first line inside this loop cycles through each "set" of values in a list expression called "tol_data".

2. In the "if" statement line, it checks to see if the BUSHING_OD is larger than the first number in the "set" AND less than or equal to the second number in the set, and if this is true, returns the third value in the set (the appropriate tolerance value) and then exits the loop.

3. The last "Return" line returns a default value of 999 if the BUSHING_OD is outside the range of the data in the table. That's just a failsafe, to make sure you've got a number coming back every time.

And so the loop returns one clean number, every time.

In the end, this setup results in a total of three expressions... One for the BUSHING_OD, one list expression for all of the tol_data, and the output expression BUSHING_CLEAR:

URL]


...and if you want to add more rows to the table, that's FAR easier than trying to wedge more IF()THEN()ELSE() statements into an expression, right?

URL]


...and with the exception of the table-based editing of the list, all of this is possible in any version since NX 8.5, when we introduced the List expression type.

Does that help? :)

Taylor Anderson
NX Product Manager, Knowledge Reuse and NX Design
Product Engineering Software
Siemens Product Lifecycle Management Software Inc.
(Phoenix, Arizona)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor