Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

Obtaining position of a list member 2

Status
Not open for further replies.

PrintScaffold

Mechanical
Sep 8, 2006
453
0
0
RU
Hello everyone!

Let's assume I have a list of some string values. It is possible to use nth function to obtain value at given position.
Does a out-of-the-box function exist to solve a reverse task - to obtain position of a given value? For example, to obtain 2 if "Trim 2" is given.

list_kve3vu.png


 
Replies continue below

Recommended for you

PrintScaffold --

There is a function for this... With a big caveat. :)

There's an OOTB function called [maybe not surprisingly] "position" that does this:

URL]


In my model I'd manually locked this particular formula to prevent inadvertent edits, hence the blue and the lock. Just ignore that here.

The caveat here is that If the string (or number) you're using for the search is not in the list, then this function does not fail particularly gracefully. You'll want to make very sure that your input matches one of your options. Play around with it, and you'll see what I mean.

Out of curiosity, what is your larger use case here? (If you're attempting dynamically-driven option menus in Product Template Studio, then there's a much better technique I can tell you about.)


Taylor Anderson
NX Product Manager, Knowledge Reuse and NX Design
Product Engineering Software
Siemens Product Lifecycle Management Software Inc.
(Phoenix, Arizona)
 
Hi Taylor! Thanks, I will have a look!
I know about the PTS solution for this case. I was looking into possibilities to emulate something similar without the PTS. :)
The larger use case is to pick options by descriptive name rather than trim number. It might be useful for some UDFs I am working on now.

 
I'm running NX 9.0.3.4 and it works for me, I'm surprised it didn't work in NX 10 for you.

Here's an expanded version that fails gracefully if the item is not found in the list (it will return -1 as the position).

Code:
IF (member( MATERIAL_STRING_INPUT, MATERIAL_LIST_NAMES, "key", Identity, "test", Equal ))(Position(MATERIAL_STRING_INPUT, MATERIAL_LIST_NAMES))else(-1)



www.nxjournaling.com
 
It does not show up in my list of functions either. There are some KF functions that can be used with the expression system, this must be one. It seems Taylor let us in on a little secret.

Edit:
PrintScaffold said:
Why none of my NX versions has it I have no idea! Maybe some obscure environment variable has to be set?

Just type it in and use it, no environment variables need to be set first.

www.nxjournaling.com
 
When I first discovered this function a few years ago, I was told that while it works as advertised, it was not considered to be 'officially' supported due to that 'failure' issue Taylor mentioned earlier. I would hope that there are plans to fix that as this is a very useful function to have particularly if you would like to use sets of List Expressions as a sort 'flat' data base.

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
 
All of the Knowledge Fusion (KF) functions are "functional" within the Expressions environment, because KF is the primary engine making Expressions work.

Back in about NX 3, we selected a subset of the full KF language and identified these functions as "DesignLogic" functions that would be visible to interactive (as opposed to programmatic) users of NX within the Expressions dialog. Initially, this subset was selected mostly because they would return a single numerical result, back in the days when NX Expressions could only store single floating point numerical values. Of course, in subsequent versions of NX, we've expanded the set of supported datatypes for Expressions and at the same time expanded support for a larger subset of the body of KF functions that are visible in the Expressions dialog.

But if you know what you're doing, there's no license preventing you from using other KF functions in Expressions. The source code for all of these KF functions is available in the NX installation, so they're not particularly secret. But be aware that once you step outside that "DesignLogic" set, things get a bit trickier, and as cowski has done above, some additional error handling may become necessary.

Does that help?

Taylor Anderson
NX Product Manager, Knowledge Reuse and NX Design
Product Engineering Software
Siemens Product Lifecycle Management Software Inc.
(Phoenix, Arizona)
 
Hi,

This post is very interesting (All of the Knowledge Fusion (KF) functions are "functional" within the Expressions environment, because KF is the primary engine making Expressions work.)

Are there another good expression functions ?

Regards
Didier Psaltopoulos
 
Status
Not open for further replies.
Back
Top