×
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

Help with Hashed Expressions from Imported Parts
2

Help with Hashed Expressions from Imported Parts

Help with Hashed Expressions from Imported Parts

(OP)
In our master part, we routinely import between 2 and 10 parts in various locations, depending on the application. Each of these imported parts are reused often and each contains two expressions that I would like to use to auto-fill multiple values in a table in the master part drawing.

The problem I am having is that after all the parts are imported, the expressions I am interested in end with a hash and a number ('#). The hash isn't a problem, but the number seems to correlate to the number of solids that exist, or have existed in the file. This is problematic because it means I can't be sure of what number will follow the hash and therefore can't have the appropriate code in the table to auto-fill based on the expression value.

In a past thread (thread561-239964: Program to remove '1 from expressions) John Baker uploaded a grip file to take off the hash and number combinations of non-repeating expressions. I am wondering if there is some way to reset the expressions so that the numbering after the hash will start at 1 and continue for as many expressions as I need for the part (so if I am interested in the expression "Cylinder_Height", the list will have "Cylinder_Height'1", "Cylinder_Height'2", etc.. for as many parts as I have imported). It would also work just as well if I could consistently anticipate the numbers that will follow the hash, no matter what they are.

I would really appreciate any help you guys could give. Thanks in advance.

RE: Help with Hashed Expressions from Imported Parts

Sorry, there is no 'reset' option which will allow the Expression system to either start over or fill-in the blanks.  In fact, some features create 'hidden expressions' which are either needed now or are reserved for when some option is toggled ON in a future edit.  So even if we did provide a reset scheme, it wouldn't fill in all the 'gaps' anyway, which would just lead to more questions so we decide to not even try and 'clean-up' these sorts of things.

John R. Baker, P.E.
Product 'Evangelist'
Product Engineering Software
Siemens PLM Software Inc.
Industry Sector
Cypress, CA
http://www.siemens.com/plm
UG/NX Museum:   http://www.plmworld.org/p/cm/ld/fid=209

To an Engineer, the glass is twice as big as it needs to be.
 

RE: Help with Hashed Expressions from Imported Parts

(OP)
I'm sorry to hear that. Are there any other suggestions regarding how I can take get the info I need to auto-fill the drawing tables? Ultimately, the two values I need from the imported file are a cylinder height (always the first feature of the imported part) and the name of the imported part. Are there other schemes besides expressions to automatically pass data like that to a tabular note in a drawing?

RE: Help with Hashed Expressions from Imported Parts

(OP)
Also, I forgot to mention it, but in this old closed thread (thread561-220545: Expressions - reset?) there is mention of a utility to reset expressions from the freeware section of the following site: www.sea4ug.com . Clearly, this site is not what it was when this thread was opened. Does anyone know if this utility is hosted anywhere else and what versions of NX it works with?

We are currently running NX5, but will be shifting over to NX8 to take advantage of some automating features in the near future.

RE: Help with Hashed Expressions from Imported Parts

2
The following code will find all expressions in the file that have any number of characters, followed by a single apostrophe, followed by 1 or more digits, followed by any number of characters. The pattern may need some tweaking for your needs.

CODE

Option Strict Off
Imports System
Imports System.Text.RegularExpressions
Imports NXOpen

Module NXJournal
Sub Main

Dim theSession As Session = Session.GetSession()
Dim workPart As Part = theSession.Parts.Work
Dim displayPart As Part = theSession.Parts.Display

Dim lw As ListingWindow = theSession.ListingWindow
Dim i as Integer = 0

'the pattern is set to look for 0 or more characters (\.*),
'  followed by a single apostrophe ('),
'  followed by 1 or more digits (\d+),
'  followed by 0 or more characters (\.*)

Dim re as New RegEx("\.*'\d+\.*")

Dim myExpressions as Expression()

myExpressions = workPart.Expressions.ToArray()

lw.Open
For Each myExp as Expression in myExpressions
    if re.IsMatch(myExp.Name) then
        lw.WriteLine(myExp.Name & " = " & myExp.RightHandSide & " evaluates to: " & myExp.Value)
        i += 1
    end if
Next

if i = 0 then
    lw.WriteLine("No expression names matched the specified regular expression")
end if

lw.Close

End Sub
End Module

RE: Help with Hashed Expressions from Imported Parts

(OP)
Thanks cowski!

With a little bit of tweaking, I am able to use that code to find all the expressions with a (') and create a new expression with a name I can fully control that links back to the original expression I am interested in, regardless of the value after the (').

The one thing I am not sure about is how to use this if the expression in question is a string? The following line:

CODE

        lw.WriteLine(myExp.Name & " = " & myExp.RightHandSide & " evaluates to: " & myExp.Value)

returns an error if the expression in question contains a string for a value. What needs to be modified to use strings?

RE: Help with Hashed Expressions from Imported Parts

I'd try (untested):

CODE

myExp.Value.ToString

RE: Help with Hashed Expressions from Imported Parts

Ok, I had a chance to look at it a little closer. Here is a revised journal.

CODE

Option Strict Off
Imports System
Imports System.Text.RegularExpressions
Imports NXOpen

Module NXJournal
Sub Main

Dim theSession As Session = Session.GetSession()
Dim workPart As Part = theSession.Parts.Work
Dim displayPart As Part = theSession.Parts.Display

Dim lw As ListingWindow = theSession.ListingWindow
Dim i as Integer = 0

'the pattern is set to look for 0 or more characters (\.*),
'  followed by a single apostrophe ('),
'  followed by 1 or more digits (\d+),
'  followed by 0 or more characters (\.*)
Dim re as New RegEx("\.*'\d+\.*")

Dim myExpressions as Expression()

myExpressions = workPart.Expressions.ToArray()

lw.Open
For Each myExp as Expression in myExpressions
    if re.IsMatch(myExp.Name) then
        'lw.WriteLine("Type: " & myExp.Type)
        if myExp.Type = "Number" then
            lw.WriteLine(myExp.Name & " = " & myExp.RightHandSide & " evaluates to: " & myExp.Value)
        else
            'myExp.Type = "String", "Boolean", "Integer", "Point", "Vector"
            lw.WriteLine(myExp.Name & " = " & myExp.RightHandSide)
        end if
        i += 1
    end if
Next

if i = 0 then
    lw.WriteLine("No expression names matched the specified regular expression")
end if

lw.Close

End Sub
End Module

RE: Help with Hashed Expressions from Imported Parts

(OP)
This has been very helpful and instructive. Not only will this allow me to auto-fill the information I originally posted this thread for, but it will also facilitate auto-filling a table with XYZ coordinate data.

Thanks again cowski!

RE: Help with Hashed Expressions from Imported Parts

Do I understand this correct, you import a specific part frequently, and it's expression , say "p71" will be used in a drawing table, and it is difficult to find the correct "p71" because there might exist more than one "p71'n".  Due to that the rename mechanism that adds "'n" each time an expression is imported.
Can't you rename the expressions in that specific part into names which are clearly unique ( such as "cyl_x_height" )and then run a journal that strips the "'n" ?


Regards,
 Tomas

RE: Help with Hashed Expressions from Imported Parts

(OP)
That is exactly what I have ended up doing, although I have just created a new expression that links back to the expression with the "'n" but with a consistent numbering system.

Thanks again to cowski for the code to get me on my way.

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