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!

Expressions NX9: "IF" statements

Status
Not open for further replies.

3dr

Automotive
Jul 10, 2004
451
I'm successfully using these to develop smart models that can be globally morphed. Typically commercial hardware that comes in a family of different sizes. But when I use conditional "if" statements I'm only able to look at a numeric expression. I would like to be able to look at more than just that. Is it possible to use an expression like "Y" "N" or an alphanumeric like "LJ.750" ???

I'm sure this is basic stuff for many of you... can you help the newb???

TIA

Dave
 
Replies continue below

Recommended for you

To address the question asked by PascalDW, I've attached a simple part file (this file was created using NX 8.0, the first version where these capabilities were available) demonstrating some ways that you can use Attributes to control the Expressions driving a model.

When you go to...

File -> Properties -> Attributes

...you'll find the following Attributes in a category titled 'User_Entry':

Blend = True

This is a Boolean Attribute controlling whether there is a blend on the model or not, using Suppress by Expression.

Blend_Radius = 10 mm

This is a 'List' Attribute offering ONLY three pre-defined Blend sizes. You MUST select one of the three choices.

Diameter = 100 mm

This is also a 'List' Attribute offering five different diameters for the cylinder, however in this case you have the choice of either selecting one of the five pre-defined sizes OR you can type in any size that you desire.

Height = 100 mm

And the last Attribute allows you to enter any desired value BETWEEN 50 and 200 mm.

Now all of these Attributes were set-up by using the tools found at...

File -> Utilities -> Attribute Templates...

...and creating what we call a 'Part File' template which means that it only effects the current part file. You can also create 'Catalogs' of attributes which can be available whenever you're creating a new part file even if you've never set up any pre-defined attributes for that part file template. Note that you do NOT need to use the Utilities -> Attribute Template... workflow if all you're doing is creating adhoc attributes on the fly, but you must go this route if you wish to set-up the various list or limits type attributes.

Anyway, I hope this helps you all better understand how attributes can be used to control many aspects of your models.

John R. Baker, P.E.
Product 'Evangelist'
Product Engineering Software
Siemens PLM Software Inc.
Industry Sector
Cypress, CA
Siemens PLM:
UG/NX Museum:

To an Engineer, the glass is twice as big as it needs to be.
 
 http://files.engineering.com/getfile.aspx?folder=295f187d-66cf-4a88-a885-fde0214a6fac&file=Attribute_to_Expression_example-1.prt
Now that is slick John, and very useful!

But I'm playing around with creating my own "Diameter" Attribute like yours and falling down badly. How did you do that?

And your "Height" Attribute Shows a Range on the left side "Value" [50, 200]
How'd you do that one????

TIA

Dave

 
Never mind I see you posted that. I spoke to soon.. sorry man.

But how can I get those attributes to report to another attribute that passes info to the BOM??

That answer completes everything I've tried to accomplish in this thread and more.

TIA

DAve
 
Hello John,

Thanks for this all-saying-example.

I am currently located in a company, Attributes are used as a communication between purchasing/manufacturing and our CAD models.
Typical large assemblies of tubes, plates and fixation elements.
Attributes are highly used.
They/I use attributes since 11-12 years ago. But we are now in a process of streamlining the new capabilities of Attributes.
A bottleneck is the old CAD Data, which is mainly re-used (cloned), contains these old (STRING type)attributes but cannot be linked to expressions who are mainly NUMBER Type. This is logical, and we are hoping to have a simple and good working journal that finds and replaces the "old" attribute with the new style attributes.
I am sure this will be possible.
Currently a external User Function program (still NX6)is used to update all the Attributes, but it will be soon outdated, because of win64 bit converting problems.

This example perfectly shows the possibilities off the new Attribute type.
And as you explained, I have to set up Attribute Templates, this is the way to go!

Many thanks.
Pascal
OFF TOPIC Closer living to Brugge then the Antwerp guy, so do you know any name from your mothers side?
Maybe they can be tracked...


 
Note that there are Expression functions (just click on the f(x) icon at the bottom, left-side of the Expression dialog) which will convert Strings to Numbers and Numbers to Strings. The two functions that you're looking for are 'MakeNumber', which will return either an Integer or a Number of a string (if there is no decimal point it returns an Integer, otherwise you get a floating-point, or 'real' number) and 'stringvalue' which returns a string of an integer/number.

John R. Baker, P.E.
Product 'Evangelist'
Product Engineering Software
Siemens PLM Software Inc.
Industry Sector
Cypress, CA
Siemens PLM:
UG/NX Museum:

To an Engineer, the glass is twice as big as it needs to be.
 
For 3dr, you can always create another attribute which is linked to the expression which is being driven by the original 'User_Entry' attribute. In the updated version of that original file I posted (the new file is attached below) I created two new attributes on-the-fly which are linked back to the model's expressions. After you update your model by changing either the User_Entry attributes 'Diameter' or 'Height', and after updating the model, the General attributes 'Cyl_Dia' and 'Cyl_Hgt' update to reflect those values. Now you can reference these attributes anywhere you wish.

John R. Baker, P.E.
Product 'Evangelist'
Product Engineering Software
Siemens PLM Software Inc.
Industry Sector
Cypress, CA
Siemens PLM:
UG/NX Museum:

To an Engineer, the glass is twice as big as it needs to be.
 
 http://files.engineering.com/getfile.aspx?folder=936b6194-44a9-4395-98f2-9b7f6c2233bb&file=Attribute_to_Expression_example-2.prt
Hei, JohnRBaker,
And can we use conditionals "IF" with constraint assemblies?
That could be useful for example with a Rubik cube, you would only allow some rotations when the perpendicular rotations are exactly a multiple of 90 degrees.
 
At the moment, the only relationship between Constraints (of any sort) and Expressions are ones with parameters and then the only thing that you can do is control the actual value of that parameter.

But speaking of NX and 'Rubik Cubes':


John R. Baker, P.E.
Product 'Evangelist'
Product Engineering Software
Siemens PLM Software Inc.
Industry Sector
Cypress, CA
Siemens PLM:
UG/NX Museum:

To an Engineer, the glass is twice as big as it needs to be.
 
At John... I see how you got that (1) attribute value back to (1) other attribute. What I'll need to do is gather the values from Multiple Attribute to get a composite catalog Number into (1) Attribute.

These (4) are the source
Attributes = Model Tonnage Stroke Mtg Options
Type = String String String String
Values = LJ 500 050 B21

This is the target attribute and it should appear like:
BOM_CAT_NO = LJ.500.050.B21


But I can't even get this far this morning. I'm failing to pull together all I've learned at the modeling level. As you can see from above I'm using "string" attributes with numeric inputs and that's tripping up my expressions. I'm using "string" because the "number" type was drop the trailing zeros after the decimal point and its confusing. This method will be more flexible if I can get it working.

Maybe I'm trying to do something that wont work at all. This expression syntax is accepted but defaults to the "wrong entry" size.

if (Attr_Tonnage=300)(38) Else (if (Attr_Tonnage=500)(44.5) Else (if (Attr_Tonnage=750)(50) Else (Wrong_Entry)))

Do I need to convert that string data to a number first to be able to do this? I see you mentioned that above.

I've attached a screen dump in case it helps.

I'm going to keep working on this till it's solved. Hope I'm not wearing you out!

TIA Dave


 
 http://files.engineering.com/getfile.aspx?folder=da82e5e2-faf5-4626-875c-75f114c7ef74&file=FAILED_SETUP.bmp
Ok, S=syntax problem solved from post above and Model is fully built.

Just need to create (1) Attribute from the (4) as shown in previous post.



 
OK, see the attached file as I think this will get you going in the right direction. Again, the file was created using NX 8.0 just in case others want to see what the solution was.

John R. Baker, P.E.
Product 'Evangelist'
Product Engineering Software
Siemens PLM Software Inc.
Industry Sector
Cypress, CA
Siemens PLM:
UG/NX Museum:

To an Engineer, the glass is twice as big as it needs to be.
 
 http://files.engineering.com/getfile.aspx?folder=04485131-ea80-4a47-89f0-9b778a86b988&file=Expression_Example_for_3dr.prt
That answer is the bomb John and exactly what I was looking for.

Thanks so much for all the help and have a great holiday!!!


Dave
 
Ok one more question. lol

Attribute, Tonnage (Dia) / Attribute , Stroke(Length)
These two combine to form the basic size of the part. But all the selections in the "list" for "Stroke" don't go with every selection in the list for "Tonnage"

I designed the expression architecture to avoid the possibility of building a model that isn't commercially available. I needed to do that.
But the Error fallout leaves the user hanging.

Is there any practical way to deal with that?? Can I get my own message to appear??? "Choose a Compatible Stroke" or something. I'm definitely stretching I know.

Maybe I should have combined those two attributes into one. I had it that way on the pilot part I did first but I abandoned it. The possible attribute "list" was sooooo long and so were all the expressions.

TIA

Dave
 
Do you have a matrix showing the legitimate combinations? Are they limited to just 'Tonnage' versus 'Stroke' or are the other variables also linked to something like 'Tonnage'?

John R. Baker, P.E.
Product 'Evangelist'
Product Engineering Software
Siemens PLM Software Inc.
Industry Sector
Cypress, CA
Siemens PLM:
UG/NX Museum:

To an Engineer, the glass is twice as big as it needs to be.
 
There are 11 other expressions looking at Tonnage to determine what size they should be. Screw diameters and depths, radii, etc...

I don't have a matrix to show how all this is put together, I kinda winged it all. But, I exported the expression list and included it as an attachment here.

I'm willing to re-construct the whole thing if there is a better architecture. This is the first of about 6 part families and I want to get it right.

Thanks

Dave
 
 http://files.engineering.com/getfile.aspx?folder=3777d927-a318-45d3-b356-65f97b113ab8&file=LJ_Series_Expressions.exp
About the Rubik video.... I guess the creator of the video doesn't try to move the pieces as in real life, he doesn't need that NX checks for any restrictions, contact..., he just creates a pre-calculated motion in the way you know is OK.

Could it be done with GRIP or NX ? (I mean a macro that modifies the constraints depending on conditions).
 
The video, which I created BTW, just rotates the blockes in a predetermined set of movements which yes, I already knew was a valid solution (I actually found a website where if you enter the description of the initial face colors that it will return a step-by-step list of steps which will solve the cube in the least number of moves). And as I previously stated, the control of constraints is not as easy as suppressing and un-suppressing features. Now I would never try this with GRIP but perhaps NX Open could tackle this, however you'd still need to find some sort of Rubik 'solver' which could be incorporated into the program or if you're good enough, you could write one yourself.

John R. Baker, P.E.
Product 'Evangelist'
Product Engineering Software
Siemens PLM Software Inc.
Industry Sector
Cypress, CA
Siemens PLM:
UG/NX Museum:

To an Engineer, the glass is twice as big as it needs to be.
 
A comment for 3dr before I go any further, it would appear that you're attempting to create some sort of model which can be used in ether a Metric or Imperical units situation. If this is true, I would highly recommend that you create two different models.

Anyway, I have an idea which could extensively reduce the number and complexity of your 'IF' statements, but first a question. It would appear that there are THREE basic sizes of whatever that you're doing based on 'tonnage', 300, 500 and 750, correct?

John R. Baker, P.E.
Product 'Evangelist'
Product Engineering Software
Siemens PLM Software Inc.
Industry Sector
Cypress, CA
Siemens PLM:
UG/NX Museum:

To an Engineer, the glass is twice as big as it needs to be.
 
OK 3dr, I made some assumptions based on what I saw in your expression sample and decided to take it to the next level and introduce you to the concept of 'List' expressions and the 'nth' function. As you can see from the attached sample file (again, saved as an NX 8.0 file) this approach is very useful when you need to set certain expression to certain values based on the value of other expressions. And as you will also see, it avoids having to create complex IF statements. In fact I basically did what you had in the sample list but I never used a single IF statement yet as you set the Tonnage or the Stroke attributes you'll see that the rest of your expressions update to the values that you wanted.

Anyway, take a look as this can save you a lot of complexity once you learn how to use 'List' expressions and then use the 'nth' function to pull values from these lists.

John R. Baker, P.E.
Product 'Evangelist'
Product Engineering Software
Siemens PLM Software Inc.
Industry Sector
Cypress, CA
Siemens PLM:
UG/NX Museum:

To an Engineer, the glass is twice as big as it needs to be.
 
 http://files.engineering.com/getfile.aspx?folder=7b65b229-5b8f-43e7-9e2e-ddf10c392110&file=Expression_List_Example_for_3dr.prt
John, Thank you again. Do you ever rest!?

This is a much improved format and really condenses things. It will take me a some time to break it down to the point where I can write my own stuff tho and I may have some questions.

First on the list is whether or not I can control the presented "list" options for the "stroke" attribute based on the selection for "tonnage"?

I can see that this is a hurdle that I'm going to see a lot more more of.



Dave

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor