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!

Help with Hashed Expressions from Imported Parts 2

Status
Not open for further replies.

kfraysur

Bioengineer
Feb 4, 2010
42
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) 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.
 
Replies continue below

Recommended for you

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
UG/NX Museum:
To an Engineer, the glass is twice as big as it needs to be.
 
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?
 
Also, I forgot to mention it, but in this old closed thread (thread561-220545) there is mention of a utility to reset expressions from the freeware section of the following site: . 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.
 
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

[COLOR=green]'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 (\.*)[/color]
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
 
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?
 
I'd try (untested):
Code:
myExp.Value.ToString
 
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
 
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!
 
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
 
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.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor