Expression Linking - journal help
Expression Linking - journal help
(OP)
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.
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 | www.hennypenny.com





RE: Expression Linking - journal help
CODE --> Basic
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 ModuleRE: Expression Linking - journal help
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@"94180/A"::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 | www.hennypenny.com
RE: Expression Linking - journal help
RE: Expression Linking - journal help
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
RE: Expression Linking - journal help
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.
RE: Expression Linking - journal help
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 TryI think that moudy1 is correct that your code has other issues, but hopefully this will get you started.
www.nxjournaling.com
RE: Expression Linking - journal help
Code errors out at line 24 (as you guessed).
Unfortunately the primitive code I posted is = to my know how on the subject...
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 | www.hennypenny.com
RE: Expression Linking - journal help
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)
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
RE: Expression Linking - journal help
CODE
www.nxjournaling.com
RE: Expression Linking - journal help
becomes...
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 | www.hennypenny.com
RE: Expression Linking - journal help
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.
RE: Expression Linking - journal help
Yes that looks like what you need to do.
RE: Expression Linking - journal help
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 | www.hennypenny.com
RE: Expression Linking - journal help
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
RE: Expression Linking - journal help
•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.
RE: Expression Linking - journal help
If it is, you'd update your code to:
CODE
www.nxjournaling.com
RE: Expression Linking - journal help
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
RE: Expression Linking - journal help
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 | www.hennypenny.com
RE: Expression Linking - journal help
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.
RE: Expression Linking - journal help
I did this
Dim text8(0) As String
text8(0) = "<X0.3@"" & curentFile & ""::Sheet_Metal_Bend_Radius>"
draftingNoteBuilder4.Text.TextBlock.SetText(text8)
MsgBox(" text8(0) =" & text8(0))
Not sure if I entered the message code correctly but the attached image is the result.
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
RE: Expression Linking - journal help
CODE
www.nxjournaling.com
RE: Expression Linking - journal help
msg box returns...
text2(0) = <X0.2@150013/011::HP_Material>
working code line looks like this
text2(0) = "<X0.2@""150013/011""::HP_Material>"
What to do?
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
RE: Expression Linking - journal help
Does this file contain the expression: HP_Material?
www.nxjournaling.com
RE: Expression Linking - journal help
Yes - HP_Material is present.
We are linking from the drawing spec text to the model file expressions that drive the sheet metal features.
If I edit drawing spec text manually to this...
<X0.2@"150013/012"::HP_Material>
I get the result that I am after.
I think we are very close but it appears that the extra quotes are required??
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
RE: Expression Linking - journal help
CODE
www.nxjournaling.com
RE: Expression Linking - journal help
Thank you sir :)
Last part of the puzzle...
- How do I overcome the annotation name changing from file to file?
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
RE: Expression Linking - journal help
Here is a code example of a selection function, it will prompt you to select a note and will then change its text:
CODE
Option Strict Off Imports System Imports NXOpen Imports NXOpen.UF Module Module2 Dim theSession As Session = Session.GetSession() Dim workPart As Part = theSession.Parts.Work Sub Main() Dim myNote As Annotations.Note If SelectNote("Select MATERIAL note", myNote) = Selection.Response.Cancel Then Exit Sub End If Dim noteText(0) As String noteText(0) = "unobtanium material" EditNoteText(myNote, noteText) End Sub Sub EditNoteText(ByVal theNote As Annotations.Note, ByVal newText() As String) Dim markId1 As Session.UndoMarkId markId1 = theSession.SetUndoMark(Session.MarkVisibility.Visible, "Edit Note") Dim draftingNoteBuilder1 As Annotations.DraftingNoteBuilder draftingNoteBuilder1 = workPart.Annotations.CreateDraftingNoteBuilder(theNote) draftingNoteBuilder1.Text.TextBlock.SetText(newText) draftingNoteBuilder1.Commit() draftingNoteBuilder1.Destroy() End Sub Function SelectNote(ByVal prompt As String, ByRef selObj As NXObject) As Selection.Response Dim theUI As UI = UI.GetUI Dim title As String = "Select a note" Dim includeFeatures As Boolean = False Dim keepHighlighted As Boolean = False Dim selAction As Selection.SelectionAction = Selection.SelectionAction.ClearAndEnableSpecific Dim cursor As Point3d Dim scope As Selection.SelectionScope = Selection.SelectionScope.WorkPart Dim selectionMask_array(0) As Selection.MaskTriple With selectionMask_array(0) .Type = UFConstants.UF_drafting_entity_type .Subtype = UFConstants.UF_draft_note_subtype End With Dim resp As Selection.Response = theUI.SelectionManager.SelectObject(prompt, _ title, scope, selAction, _ includeFeatures, keepHighlighted, selectionMask_array, _ selObj, cursor) If resp = Selection.Response.ObjectSelected OrElse resp = Selection.Response.ObjectSelectedByName Then Return Selection.Response.Ok Else Return Selection.Response.Cancel End If End Function Public Function GetUnloadOption(ByVal dummy As String) As Integer 'Unloads the image when the NX session terminates GetUnloadOption = NXOpen.Session.LibraryUnloadOption.AtTermination End Function End Modulewww.nxjournaling.com
RE: Expression Linking - journal help
- Is your answer different for a new file?
- Is it possible to modify the template/s (Drawing, Sheet) note instance/s to some specific name that wont randomize?
P.S. the Unobtainium reference made me LOL.
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
RE: Expression Linking - journal help
Yes, you can give the note a unique name or attribute to find it later. To name a note object, right click on it and choose properties and pick the general tab (if necessary); enter a name and press OK. If you hover over the note object, it will show you the assigned name in a 'tooltip' style popup.
Below is a variation on the previous code; this version will look for a note named "material" and will change the text if found. If the note is not found, it will prompt you to select a note, to which it will then assign the "material" name (for any future runs of the journal).
CODE
Option Strict Off Imports System Imports NXOpen Imports NXOpen.UF Module Module1 Dim theSession As Session = Session.GetSession() Dim workPart As Part = theSession.Parts.Work Sub Main() Dim myNote As Annotations.Note = FindNoteByName("material") If myNote Is Nothing Then If SelectNote("Select MATERIAL note", myNote) = Selection.Response.Cancel Then Exit Sub Else myNote.SetName("MATERIAL") End If End If Dim noteText(0) As String noteText(0) = "other material" EditNoteText(myNote, noteText) End Sub Function FindNoteByName(ByVal noteName As String) As Annotations.Note 'search for note with the given name 'return first note found with the name For Each tempNote As Annotations.Note In workPart.Notes If tempNote.Name.ToUpper = noteName.ToUpper Then Return tempNote End If Next Return Nothing End Function Sub EditNoteText(ByVal theNote As Annotations.Note, ByVal newText() As String) Dim markId1 As Session.UndoMarkId markId1 = theSession.SetUndoMark(Session.MarkVisibility.Visible, "Edit Note") Dim draftingNoteBuilder1 As Annotations.DraftingNoteBuilder draftingNoteBuilder1 = workPart.Annotations.CreateDraftingNoteBuilder(theNote) draftingNoteBuilder1.Text.TextBlock.SetText(newText) 'Dim nXObject1 As NXObject 'nXObject1 = draftingNoteBuilder1.Commit() draftingNoteBuilder1.Commit() draftingNoteBuilder1.Destroy() End Sub Function SelectNote(ByVal prompt As String, ByRef selObj As NXObject) As Selection.Response Dim theUI As UI = UI.GetUI Dim title As String = "Select a note" Dim includeFeatures As Boolean = False Dim keepHighlighted As Boolean = False Dim selAction As Selection.SelectionAction = Selection.SelectionAction.ClearAndEnableSpecific Dim cursor As Point3d Dim scope As Selection.SelectionScope = Selection.SelectionScope.WorkPart Dim selectionMask_array(0) As Selection.MaskTriple With selectionMask_array(0) .Type = UFConstants.UF_drafting_entity_type .Subtype = UFConstants.UF_draft_note_subtype End With Dim resp As Selection.Response = theUI.SelectionManager.SelectObject(prompt, _ title, scope, selAction, _ includeFeatures, keepHighlighted, selectionMask_array, _ selobj, cursor) If resp = Selection.Response.ObjectSelected OrElse resp = Selection.Response.ObjectSelectedByName Then Return Selection.Response.Ok Else Return Selection.Response.Cancel End If End Function Public Function GetUnloadOption(ByVal dummy As String) As Integer 'Unloads the image when the NX session terminates GetUnloadOption = NXOpen.Session.LibraryUnloadOption.AtTermination End Function End Modulewww.nxjournaling.com