Continue to Site

Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

  • Congratulations cowski on being selected by the Eng-Tips community for having the most helpful posts in the forums last week. Way to Go!

Expression Linking - journal help 2

Status
Not open for further replies.

c0pp3r

Mechanical
May 4, 2012
25
Hello all,

NX7.5
TC 8.3.3

I am attempting to automate the modification of our title block material text, linking it to its parent part file defined expression value. Currently we do this...

Edit existing text/remove current value/relationships/insert expression/link to part file/select component item from assy nav/select uniquely named expression/done. Repeat this process for each desired value per sheet.

My problem is when recording these steps via journal the Component part file selection is a variable that needs auto-populated based on the drawing I have loaded. How can i accomplish this?

Thanks in advance.

Matt Smith, Principal Designer
(o) 937.456.8728
1219 US 35 West P.O. Box 60
Eaton, OH 45320
msmith@hennypenny.com |
 
Replies continue below

Recommended for you

The following will return the file names of all the components. Will this get what you need?

Code:
Imports System
Imports NXOpen
Imports NXOpen.Assemblies
Imports NXOpen.UF


Module list_file_name_of_each_component

	Sub Main()
		Dim lw As ListingWindow = session.GetSession.ListingWindow
		lw.Open()
		Try
			Dim part1 As Part = session.GetSession.Parts.Work
			Dim c As Component = part1.ComponentAssembly.RootComponent
			Dim children As Component() = c.GetChildren()
			For Each child As Component In children
				lw.WriteLine("The Component full path name is: " & GetComponentFullPath(child))
			Next
		Catch e As Exception
			lw.WriteLine("Failed: " & e.Message)
		End Try
	End Sub

	Function GetComponentFullPath(ByVal comp As Assemblies.Component) As String
		Dim partName As String = ""
		Dim refsetName As String = ""
		Dim instanceName As String = ""
		Dim origin(2) As Double
		Dim csysMatrix(8) As Double
		Dim transform(3, 3) As Double
		UFSession.GetUFSession.Assem.AskComponentData(comp.Tag, partName, refsetName, _
			instanceName, origin, csysMatrix, transform)
		Return partName
	End Function
End Module

 
moudy1,

If I record my mouse clicks during a material expression link as I described above I can then play the recorded journal back (within the same part/drawing file) and journal succeeds. If I play this same journal on a different part/drawing file it fails to modify the desired text.

So in looking at the journal I found this line item...

Dim text2(0) As String
text2(0) = "<X@"[highlight #FCE94F]94180/A[/highlight]"::HP_Material>"
draftingNoteBuilder1.Text.TextBlock.SetText(text2)

My thought was if i could apply a UG ask part number and revision to populate these lines i would have it.
I only dabble in the code world so whether or not what you have provided above will accomplish this IDK, but thanks for the reply I appreciate it.

Does that help?

Thanks again.

Matt Smith, Principal Designer
(o) 937.456.8728
1219 US 35 West P.O. Box 60
Eaton, OH 45320
msmith@hennypenny.com |
 
When you say "it fails to modify the desired text" does the journal run or does it error complaining about line 24 or some other line #?
I'm guessing it errors (unless the files were created from the same part file) or picks the wrong note because the journal you recorded is just looking for an annotation object named "HANDLE R-39135".
If my guess is correct you will need to come up with another method to identify the notes to change. Could cycle through all the notes and and find them by the text such as "HP_Material" if that is a constant or have the user select each note. The latter would require more user intervention but would be less than you are doing manually.
 
Since you are using TeamCenter and need to get the part number and revision, try this code:

Code:
        Dim currentFile As String
        Dim strRevision As String

        Try

            currentFile = workPart.GetStringAttribute("DB_PART_NO")
            strRevision = workPart.GetStringAttribute("DB_PART_REV")
            currentFile = currentFile & "/" & strRevision

        Catch ex As NXException
            MsgBox(ex.ErrorCode & ": " & ex.Message)
        End Try

I think that moudy1 is correct that your code has other issues, but hopefully this will get you started.

www.nxjournaling.com
 
Moudy1 -
Code errors out at line 24 (as you guessed).
Unfortunately the primitive code I posted is = to my know how on the subject...
[li]Turn on the journal/macro recording[/li]
[li]Click through your command progression[/li]
[li]Stop the journal[/li]
[li]Play back the journal and cross your fingers.[/li]
Specifically the actions I am recording = Select on screen the piece of text that I wish to modify/linking that text to the expression whose value I want to display/Repeat for the second piece of text/Change sheets and repeat. This is a repetitve task that we are performing for every Sheet Metal Parts title block entry for material and bend radius.
Your comment about the name of the text makes me wonder... is it possible for to name the template files text a known value for these 2 pieces of text to remedy the cycling or user interaction that you mentioned?

cowski -
I will atempt to add the code you supplied.

Thanks for the help :)

Matt Smith, Principal Designer
(o) 937.456.8728
1219 US 35 West P.O. Box 60
Eaton, OH 45320
msmith@hennypenny.com |
 
cowski -
I saved the code you supplied into an independent journal,
Ran it against a couple of files and I keep getting these errors... (screen shot attached)
[li]Line 16: Name 'workPart' is not declared[/li]
[li]Line 17: Name 'workPart' is not declared[/li]
Im sure I have done something incorrectly, can you hint me as to what I am missing?

Thanks.

Matt Smith, Principal Designer
(o) 937.456.8728
1219 US 35 West P.O. Box 60
Eaton, OH 45320
msmith@hennypenny.com | www.hennypenny.com
 
 http://files.engineering.com/getfile.aspx?folder=c010358b-2760-4d01-967c-f01bbce75e65&file=cowski.JPG
At the beginning of most recorded journals you have the following code, add it if it is not there:

Code:
Dim theSession As Session = Session.GetSession()
Dim workPart As Part = theSession.Parts.Work

www.nxjournaling.com
 
Ok... that gets me past that error, now Im assuming I replace the line items containing the specific part/rev I used when creating this journal with your introduced variable ?? of currentFile? Like this...

[li]text8(0) = "<X0.3@""93638/A""::Sheet_Metal_Bend_Radius>"[/li]

becomes...

[li]text8(0) = "<X0.3@""currentFile""::Sheet_Metal_Bend_Radius>"[/li]

Am I even close?
LOL, I love messing with this stuff.

Thanks again.

Matt Smith, Principal Designer
(o) 937.456.8728
1219 US 35 West P.O. Box 60
Eaton, OH 45320
msmith@hennypenny.com |
 
The name I spoke of is more of an object id than a name. Every entity in NX has an object id. If you select from the main menu information... object and select a note or any entity for that matter at the bottom of the information window you will see Note - ID and a set of numbers. If you use the part you created this journal from and select the same note you should see Note - ID 39135. This will be unique for each entity that you create. The only way they are the same is by dumb luck or if you do a save as or have that entity already defined in your template part.
I think what you are wanting to do will be pretty easy, we just need more information.
How was the titleblock created with its current value? Is it part of a template or save as on existing file or imported? Do they all have the same piece of text in them now?
Is the expression name the same in each part? Your journal had "HP_Material" and "Sheet_Metal_Bend_Radius" is this the same in each file?
If you could create or have dummy parts you could supply so I could see the current state.
 
You must have posted as I was replying.
Yes that looks like what you need to do.
 
moudy1

No dice... the proposed code change from my earlier post runs without error, but does not modify the targeted text (or any text)? IDK why??

Matt Smith, Principal Designer
(o) 937.456.8728
1219 US 35 West P.O. Box 60
Eaton, OH 45320
msmith@hennypenny.com |
 
moudy1

Tile block text value is the default from template part if creating from scratch. Save as would present the text value from the parent part.

Expression name is common for all sheet metal parts.

I have attached a sample drawing.prt and its associated model.prt.

I hope this helps
Thanks.

Matt Smith, Principal Designer
(o) 937.456.8728
1219 US 35 West P.O. Box 60
Eaton, OH 45320
msmith@hennypenny.com | www.hennypenny.com
 
In place of
•text8(0) = "<X0.3@""currentFile""::Sheet_Metal_Bend_Radius>"
Put
•text8(0) = "<X0.3@""" & currentFile & """::Sheet_Metal_Bend_Radius>"

and in the example you sent me there was an underscore before the rev so change
currentFile = currentFile & "/" & strRevision
to
currentFile = currentFile & "_" & strRevision
in the code snippet cowski sent.



 
The code I posted will give you the part number and rev of the work part. If you are in the drawing file and are using the master model method (model is a component of the drawing file), it will probably not return what you want. First, I'd recommend checking the value of currentFile to see if it is what you want...

If it is, you'd update your code to:

Code:
text8(0) = "<X0.3@" & currentFile & "::Sheet_Metal_Bend_Radius>"

www.nxjournaling.com
 
moudy1 said:
and in the example you sent me there was an underscore before the rev so change
currentFile = currentFile & "/" & strRevision
to
currentFile = currentFile & "_" & strRevision

This will really depend on your Teamcenter settings. TC has no problem using "/" as a delimiter between the part number and rev, but when you export files to a native filesystem, the "/" is an illegal character in the file name and so gets converted to an underscore. You will want to use whatever delimiter(s) TC is set to use.

www.nxjournaling.com
 
Good morning,

I updated my line entries for "current file".
Code runs without error but does not modify text?

cowski - How do I check the value of currentFile?

Thanks for all the help.

Matt Smith, Principal Designer
(o) 937.456.8728
1219 US 35 West P.O. Box 60
Eaton, OH 45320
msmith@hennypenny.com |
 
Put the following line after each line where you changed the part number and change the text4 number to match.

MsgBox(" text4(0) =" & text4(0))

This will put up a message on your screen displaying what it is trying to change the text to. Make sure it matches what you would have entered.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor