×
INTELLIGENT WORK FORUMS
FOR ENGINEERING PROFESSIONALS

Log In

Come Join Us!

Are you an
Engineering professional?
Join Eng-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Eng-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Jobs

Obtaining position of a list member
2

Obtaining position of a list member

Obtaining position of a list member

(OP)
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.

www.cadroad.com

RE: Obtaining position of a list member

PrintScaffold --

There is a function for this... With a big caveat. smile

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



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)

RE: Obtaining position of a list member

(OP)
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.

www.cadroad.com

RE: Obtaining position of a list member

(OP)
Just tried and discovered that I have no access to this function OOTB. Either it appeared only in NX11 (I tried in 8.5 and 10), or you have customized your NX to have it and forgot about it! :)

www.cadroad.com

RE: Obtaining position of a list member

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

RE: Obtaining position of a list member

(OP)
Really should be OOTB, I found a documentation for it.

Why none of my NX versions has it I have no idea! Maybe some obscure enviroment variable has to be set?

www.cadroad.com

RE: Obtaining position of a list member

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:

Quote (PrintScaffold)

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

RE: Obtaining position of a list member

(OP)
That is the reason I thought I was missing it! Turned out that I have it and it works. Thank you!

www.cadroad.com

RE: Obtaining position of a list member

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

RE: Obtaining position of a list member

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)

RE: Obtaining position of a list member

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
http://www.psi-cad.fr

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Eng-Tips Forums free from inappropriate posts.
The Eng-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Eng-Tips forums is a member-only feature.

Click Here to join Eng-Tips and talk with other members!


Resources