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!

making part name "1234567" into "12345 67" using EXPRESSION FUNCTIONS 2

Status
Not open for further replies.

caddanimal

Mechanical
Jan 15, 2016
1
I am using NX 9.0.3.4 .......

i want to use functions in the EXPRESSIONS page to take the value from ug_askCurrentWorkPart()and add a " " at the Nth character.....

ex: 1234567 becomes 12345 67

However, first I need to be able to determine if the part name is to be split as shown above.... back-tracking here... there are two kinds of part numbers....

A12345.prt (most structural and assembly models)

1234567.prt (hardware part files)

if I can use IF THEN ELSE logic to determine what kind of part number it is, first, then I can somehow process the 1234567.prt file name so that I can store "12345 67" into a new parameter DB_PARTNO

Thanks in advance!



 
Replies continue below

Recommended for you

Key functions here are:

Code:
splitString ( [string], [char for splitting] )
subString ( [string], [start position], [end position] )
ug_rexp_match ( [string], [regular expression to match] )

Pseudocode would be to:

Code:
a) retrieve the filename as a string
b) split the ".prt" off the end of the string
c) compare the base part name against a regular expression for whatever pattern you're after (Here, looking for one letter followed by five numbers)
d) if the base part name matches the pattern...
   d1) then add the space at the desired position...
   d2) else return the original base name.  :-)

URL]


URL]


URL]


And that DB_PARTNO expression looks like this, in expanded mode:

Code:
@{
$base_name << first ( splitString(part_filename, ".") );
$new_name << if ( ug_rexp_match( $base_name, "[a-zA-Z]{1}[0-9]{5}" ) ) 
then ( subString($base_name, 1, space_position) + " " + subString($base_name, space_position+1, length($base_name)) ) 
else ($base_name);
}

Good little example of embedding some more advanced Knowledge Fusion logic in an expression. :)

Make sense?

Taylor Anderson
NX Product Manager, Knowledge Reuse and NX Design
Product Engineering Software
Siemens Product Lifecycle Management Software Inc.
(Phoenix, Arizona)
 
That is some terrific information on expressions. I think some of those functions are undocumented in NX.
 
aluminum2 --

Thanks! And you're kind of right. :)

The functions available inside expressions are all using the Knowledge Fusion (KF) language, and fundamentally, any KF function is fair game for use within an Expression formula. The important thing to remember is that there are two (or three, depending on how you're counting) sets of KF functions available inside NX.

1. Back in NX 3 when we shifted expressions evaluation to use KF, we only had "Number" expressions. And so because many of the KF functions returned other datatypes like strings or lists, we chose a subset of the most useful KF functions and added a little "DesignLogic" keyword to them, identifying them as functions that should be visible and available in the Functions dialog within the [numbers-only] Expressions world. As we've added the other datatypes to NX expressions over the years (strings, lists, integers, Booleans, etc.) we've added more functions to support these, but...

2. There's still a large set of KF functions that do not have the "DesignLogic" designation, and thus don't show up in the Expressions dialog. Most of these are very application-specific, and wouldn't make sense at all in the Expressions world. Others are very useful (like the REGEX match above) but quite complicated to use, and so in an attempt to balance utility against usability we don't display (and don't plan to display) every single KF function in the Expressions dialog. But they're there, lurking in the UGII/dfa folder inside the NX install, where an ambitious user can see them and search them and use them as needed. I commonly use the "Find in files" feature in TextPad (or any decent text editor) to dive through these, hunting for goodies.

3. The third set of really useful functions are the set that have been created for Check-Mate. There are hundreds of these, most doing some kind of interesting query of the model. Again, many of these are not very helpful directly in an Expressions context, and so we don't expose them through the "DesignLogic" tag, but as you might suspect, there's some really good stuff in there, too. These are located in the design_tools\checkmate\dfa folder within the NX install, and again, a good text editor will usually have the ability to search these nicely.

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