×
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

Expression Linking - journal help
2

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.

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

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

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 Module 

RE: Expression Linking - journal help

(OP)
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@"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

Can you share your journal you created?

RE: Expression Linking - journal help

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.

RE: Expression Linking - journal help

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

RE: Expression Linking - journal help

(OP)
Moudy1 -
Code errors out at line 24 (as you guessed).
Unfortunately the primitive code I posted is = to my know how on the subject...
  • Turn on the journal/macro recording
  • Click through your command progression
  • Stop the journal
  • Play back the journal and cross your fingers.

  • 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

    (OP)
    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)
  • Line 16: Name 'workPart' is not declared
  • Line 17: Name 'workPart' is not declared

  • 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

    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

    RE: Expression Linking - journal help

    (OP)
    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...

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


  • becomes...

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


  • 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

    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.

    RE: Expression Linking - journal help

    You must have posted as I was replying.
    Yes that looks like what you need to do.

    RE: Expression Linking - journal help

    (OP)
    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 | www.hennypenny.com

    RE: Expression Linking - journal help

    (OP)
    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

    RE: Expression Linking - journal help

    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.



    RE: Expression Linking - journal help

    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

    RE: Expression Linking - journal help

    Quote (moudy1)

    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

    RE: Expression Linking - journal help

    (OP)
    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 | www.hennypenny.com

    RE: Expression Linking - journal help

    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.

    RE: Expression Linking - journal help

    (OP)
    moudy1

    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

    Too many double quotes, try changing it to this:

    CODE

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

    www.nxjournaling.com

    RE: Expression Linking - journal help

    (OP)
    modified double quotes, runs without error, no text modification - DOOHHH!.

    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

    Is the 150013/011 file the drawing spec or the model file?
    Does this file contain the expression: HP_Material?

    www.nxjournaling.com

    RE: Expression Linking - journal help

    (OP)
    150013/011 = Model file.
    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

    In that case, try this:

    CODE

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

    www.nxjournaling.com

    RE: Expression Linking - journal help

    (OP)
    TAH DAH... COWSKI = Genious!
    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

    If you are modifying existing files, the easiest way is to add a selection function that will allow the user to select the note they want to edit.

    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 Module 

    www.nxjournaling.com

    RE: Expression Linking - journal help

    (OP)
    Most of the existing files will already have these expression links completed.
    - 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

    Quote (c0pp3r)

    Is it possible to modify the template/s (Drawing, Sheet) note instance/s to some specific name that wont randomize?

    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 Module 

    www.nxjournaling.com

    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