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

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
 
 http://files.engineering.com/getfile.aspx?folder=e2555068-abe8-4ab6-8a03-719ece641011&file=messagebox.JPG
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 |
 
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 |
 
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 |
 
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
 
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 |
 
c0pp3r said:
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
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor