Continue to Site

Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

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

Modify expression with input from another expression

Status
Not open for further replies.

srAndritz

Mechanical
Sep 15, 2015
8
I want to itterate the value of one expression (measurement) with input from another expression (length)
The first expression is directly relatetd to the second one.

I want to start with a value (say 2000) for the second expression (exp2), the first expression (exp1) is then 414.8119359.... (measured value)
I want to be able to set a value for instance 450.00 as a target value and a step value, for instance 10.
I want the code to function something like this:

If exp1 < target
then exp2 = exp2-step
Else end if
'loop this while exp1 < target

step = step/2
'smaller itteration steps as exp1 gets closer to target value

If exp1 > target
then exp2 = exp2+step
Else end if

and then i want to loop this over and over until exp1 reaches target value with at least 2 decimals precision.

I intend to build on this with excel imports and exports of values , i think i can handle that part but i really need some help with the itteration part.
I attached a simple partfile to further show how i want i to function.
I work in NX10 even though the part file is from NX8. I have no code to start from really and i don't expect a ready to go script in return but something to get me started :)
 
 http://files.engineering.com/getfile.aspx?folder=41e418ab-8c99-4f68-a1dc-b7686fea6f82&file=example.prt
Replies continue below

Recommended for you

There is no way to 'write' loops into the expression system using the approach you described. The expression solver only supports single pass solutions.

However, NX does offer you a couple of approaches for doing something like this, one that can be done inside the NX model using the 'Optimization' tool, the other, doing this using the 'Goal Seek' capabilities of the Modeling Spreadsheet.

The first of these two option, the 'Optimization' tool, which is the officially recommended approach, does require the purchase of an add-on module, the 'Optimization Wizard'. So if you already have this licence, then it can be found at the bottom of the 'More' panel on the 'Tools' ribbon tab (or you could just use the Command Finder and enter 'optimization').

The second approach, using the Modeling Spreadsheet, requires no additional licenses but does require that you set-up a spreadsheet using the builtin Goal Seek feature.

To give you an idea of how the Spreadsheet approach works, I've include an example file and video showing you how to run the goal seek.

One of these two approaches should give you what you need.

John R. Baker, P.E.
Product 'Evangelist'
Product Engineering Software
Siemens PLM Software Inc.
Digital Factory
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=8cd04e60-529b-4899-869d-8993442ba5d1&file=Beer_glass_demo.zip
Ah, ok, thank you for the response. Shouldn't it be possible to do something like:

For I=0 to 100000
"the code"

I=I+1
If |exp1-target| < 0,001
end For



100000 itterations should definitely be enough :)
I have done most of my (very limited) programming in Matlab so if this way of thinking doesent work in NX please let me know.
 
There is no iterative behavior within the expression system. That's why we rely on things like the optimization function and/or goal seek in the spreadsheet. Or you can always write NX Open application that when run would do the iteration and then update the expressions. Matlab works like a spreadsheet, just one that's optimized to provide solutions for mathematical and/or engineering type problems. You can always use the Maple interface that we provide as part of the expression system which offers virtually all the capabilities of Matlab and it can be linked to your part model via the expression system and it's ability to interface with a Maple Worksheet. And we're working on embedding capabilities like that to an even greater degree in future versions of NX.

To learn more about the Maple Worksheet Integration functionality, simply open your NX Help file and do a search on "Maple". Now there is no special NX licence needed to hook a Maple Worksheet to an NX part file via the expression system, but you will need to purchase Maple, just like you having to purchase Matlab.

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

To an Engineer, the glass is twice as big as it needs to be.
 
John Baker said:
There is no iterative behavior within the expression system.

That's not completely accurate... :)

The Knowledge Fusion language underlying expressions supports iterative loops quite nicely, and there are lots of examples of OOTB DesignLogic functions that use programmatic iteration to calculate answers. I just posted an answer on another thread that included this, in fact. (...which reminded me to reply to this thread.) :)

But there are limits on what can/should be done with iteration within expressions. We actively discourage (read: aggressively prevent) "NX model updates within NX model updates", and this is where you'll find the roadblock down this path. And the road sign announcing the dead end will look a lot like this:

URL]


Iteration that doesn't include model updates is a pretty handy thing. But we've deliberately chosen not to expose as much of the iterative KF syntax within Expressions, specifically, because it's pretty easy to find that dead end. But iterating through a list of data to choose (or calculate) a best value (for example) can be done without actually causing an NX update to occur, and so NX will allow this. And again, many OOTB DesignLogic functions already do this internally.

But getting back to your specific example...

Anything with a measurement feature in the loop is necessarily going to be performing model updates. And so as John describes, the NX Optimization function is probably the best way to do the kind of iteration you're describing. This function provides the framework for executing a large number of model updates in an organized way without causing recursion or infinite loops -- and is designed to gracefully handle occasional model update failures in corner cases, too.

Does that help a bit?

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