Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

NX2206 Custom Journal Breaks Hole and Thread Callout 1

Status
Not open for further replies.

jtozer

Aerospace
Aug 8, 2018
12
0
0
US
I have the below journal that pulls attributes from components to populate a tabular note in drafting. We recently changed to v2206 from v1965 and now, after the custom journal is ran, the Hole and Thread Callout tool no longer highlights features for selection. This problem goes away if you change sheets or add a new base view, potentially other ways as well, but I haven't found more yet.

Does anyone have some insight into what may be causing this issue? Is my journal holding onto some resource that I need to dispose of or close? We use this journal daily in my department, so I would really like to figure this out.

Code:
' NX 1965
Option Strict Off
Imports System
Imports NXOpen
Imports NXOpen.UF
Imports NXOpenUI

Module NXJournal
    Dim theUI As UI = UI.GetUI()
    Dim theSession As NXOpen.Session = NXOpen.Session.GetSession()
    Dim theUFSession As UFSession = UFSession.GetUFSession()
    Dim workPart As NXOpen.Part = theSession.Parts.Work

    Sub Main(ByVal args() As String)

        theUFSession.Ui.SetCursorView(0)

        Dim obCount As Integer = theUI.SelectionManager.GetNumSelectedObjects 'Get the number of objecs that were selected when the journal started
        Dim dispPart As NXOpen.Part = theSession.Parts.Display 'Get the currently displayed part 
        Dim selectUserObject As Selection.Response 'Set up dynamic selection of table and componet
        Dim userObject As NXObject = Nothing 'Initialize object selection variable
        Dim curAssy As NXOpen.Assemblies.ComponentAssembly = dispPart.ComponentAssembly 'Get currentlly displayed assembly
        Dim childComps() As Assemblies.Component = curAssy.RootComponent.GetChildren() 'Get list of currently displayed assembly's child components
        'Set Undo mark
        Dim markId1 As NXOpen.Session.UndoMarkId = Nothing
        markId1 = theSession.SetUndoMark(NXOpen.Session.MarkVisibility.Visible, "Edit Cell")

        Dim table1 As NXOpen.Tag = Tag.Null 'Initialize attributes table variable
        Dim component1 As NXOpen.Assemblies.Component = Nothing 'Iniialize selected component variable

        'Check selected objects for tabular note (TableSection) and component
        For i As Integer = 0 To obCount - 1
            'If table already selected, set table1 variable to selected table
            If theUI.SelectionManager.GetSelectedTaggedObject(i).GetType() = GetType(NXOpen.Annotations.TableSection) Then
                theUFSession.Tabnot.AskTabularNoteOfSection(theUI.SelectionManager.GetSelectedTaggedObject(i).Tag, table1)
                'If component already selected, set component1 variable to selected component
            ElseIf theUI.SelectionManager.GetSelectedTaggedObject(i).GetType() = GetType(NXOpen.Assemblies.Component) Then
                component1 = theUI.SelectionManager.GetSelectedTaggedObject(i)
            Else
                'Troubleshoot object type of selected objects
                'MsgBox(theUI.SelectionManager.GetSelectedTaggedObject(i).GetType().ToString)
            End If
        Next i

        'If no component selected, prompt user to select component
        If IsNothing(component1) Then
            'MsgBox("here")
            Try
                'object type 63 is "Exploded Component" which is apparently the object type components in drafting views have
                selectUserObject = SelectAnObject("Select the component you want to get attributes from", userObject, 63, "Select Component to Pull Attributes")
                'MsgBox(userObject.GetType.ToString & " | " & userObject.Name.ToString)
                If userObject.GetType = GetType(NXOpen.Assemblies.Component) Then
                    component1 = userObject
                ElseIf userObject.GetType = GetType(NXOpen.Assemblies.ExplodedComponent) Then
                    Dim exComp As NXOpen.Assemblies.ExplodedComponent = userObject
                    component1 = exComp.GetComponent
                Else
                    Echo("Populate Attributes Table: Selection was not component")
                End If
            Catch ex As Exception
                Echo("Populate Attributes Table: " & ex.Message & " | Error thrown in user component select")
                Exit Sub
            End Try

        End If

        'If no table selected, prompt user to select table
        If table1 = Tag.Null Then
            Try
                selectUserObject = SelectAnObject("Select the table you want to populate", userObject, 165, "Select the Table to Populate")
                If userObject.GetType = GetType(NXOpen.Annotations.TableSection) Then
                    theUFSession.Tabnot.AskTabularNoteOfSection(userObject.Tag, table1)
                Else
                    Echo("Populate Attributes Table: Table was not selected")
                End If
            Catch ex As Exception
                Echo("Populate Attributes Table: " & ex.Message & " | Error thrown in user table select")
                Exit Sub
            End Try
        End If


        Dim sectionCount As Integer = 0
        theUFSession.Tabnot.AskNmSections(table1, sectionCount)
        'Echo("  Sections: " & sectionCount)

        Dim numRows As Integer = 0, numCols As Integer = 0

        'Get tag of each cell to edit in the tabular note
        theUFSession.Tabnot.AskNmRows(table1, numRows)
        theUFSession.Tabnot.AskNmColumns(table1, numCols)

        Dim rowTag As NXOpen.Tag = NXOpen.Tag.Null
        Dim colTag As NXOpen.Tag = NXOpen.Tag.Null
        Dim theCell As NXOpen.Tag = NXOpen.Tag.Null
        Dim tabCells(5) As NXOpen.Tag

        For r As Integer = 0 To numRows - 2
            Try
                theUFSession.Tabnot.AskNthRow(table1, r, rowTag)
                theUFSession.Tabnot.AskNthColumn(table1, 1, colTag)
                theUFSession.Tabnot.AskCellAtRowCol(rowTag, colTag, theCell)
                tabCells(r) = theCell
            Catch ex As Exception
                Echo("Populate Attributes Table: " & ex.Message & " | Error thrown in get table info")
            End Try

        Next

        'Get Quantity of components in assembly. Will grab total number of components in the parent assembly of the selected component
        '!!! NOT LINKED TO PARTS LIST !!! (would love to know how to do that though)
        Dim componentFileName As String
        Dim componentCount As Integer = 0
        Dim compParent As Assemblies.Component = component1.Parent
        Dim compParentCount As Integer = 0
        Dim parChildComps() As Assemblies.Component = Nothing
        Try
            Dim callouttext As Integer = component1.GetUserAttributeAsString("CALLOUT", NXObject.AttributeType.Any, 0)
        Catch ex As Exception
            Dim resp As Integer = theUI.NXMessageBox.Show("Error", NXMessageBox.DialogType.Error, "Error getting Callout, component is not in Parts List")
        End Try

        componentFileName = component1.Name.ToString 'Trim(NXInputBox.GetInputString("Enter the file name of the component"))
        'Echo("Journal-Populate Attributes Table | Component Parent is " & component1.Parent.Name.ToString)
        'Get count of selected component in displayed assembly
        For i As Integer = 0 To UBound(childComps)
            parChildComps = childComps(i).GetChildren
            If childComps(i).Name = componentFileName Then
                componentCount += 1
            ElseIf UBound(parChildComps) > 0 Then
                'Echo("Journal-Populate Attributes Table | Sub Assy " & childComps(i).Name & " parChildComps.Count = " & UBound(parChildComps))
                For j As Integer = 0 To UBound(parChildComps)
                    If parChildComps(j).Name = componentFileName Then
                        componentCount += 1
                    End If
                Next
            End If
        Next

        'componentCount = NXInputBox.GetInputString("Enter the component quantity") 'component1.GetRealQuantity(component1.GetComponentQuantityType)

        'Populate table
        Try
            theUFSession.Tabnot.SetCellText(tabCells(0), "<W" & componentFileName & "@CALLOUT>") 'Callout
            theUFSession.Tabnot.SetCellText(tabCells(1), "<W" & componentFileName & "@DESCRIPTION>") 'Description
            theUFSession.Tabnot.SetCellText(tabCells(2), componentCount) 'Quantity
            theUFSession.Tabnot.SetCellText(tabCells(3), "<W" & componentFileName & "@MATERIAL>") 'Material
            theUFSession.Tabnot.SetCellText(tabCells(4), "<W" & componentFileName & "@Size>") 'Size
            theUFSession.Tabnot.SetCellText(tabCells(5), "<W" & componentFileName & "@TREATMENT>") 'Treatment
            'theUFSession.Tabnot.AskCellText(tabCells(0), callouttext)
            'MsgBox(callouttext)
        Catch ex As Exception
            MsgBox("Populate Attributes Table: " & ex.Message)
        End Try

        theUI.SelectionManager.ClearGlobalSelectionList()

    End Sub

    Sub Echo(ByVal output As String)

        theSession.ListingWindow.Open()
        theSession.ListingWindow.WriteLine(output)
        theSession.LogFile.WriteLine(output)

    End Sub

    Public Function GetPlistTag(ByRef partTag As NXOpen.Tag) As NXOpen.Tag

        Dim tempTag As NXOpen.Tag = NXOpen.Tag.Null
        Dim type As Integer
        Dim subtype As Integer

        Do
            theUFSession.Obj.CycleObjsInPart(partTag, UFConstants.UF_tabular_note_type, tempTag)

            theUFSession.Obj.AskTypeAndSubtype(tempTag, type, subtype)

            If subtype = UFConstants.UF_parts_list_subtype Then
                Return tempTag
            End If

        Loop Until tempTag = NXOpen.Tag.Null

        Return Tag.Null
    End Function

    Public Function GetComponentQty(calloutID As Integer)
        Dim myPList As NXOpen.Tag = NXOpen.Tag.Null
        Dim dispPart As NXOpen.Tag = theSession.Parts.Display.Tag

        myPList = GetPlistTag(dispPart)

        Dim rowTag As NXOpen.Tag = NXOpen.Tag.Null
        Dim colTag As NXOpen.Tag = NXOpen.Tag.Null
        Dim theCell As NXOpen.Tag = NXOpen.Tag.Null
        Dim tabCells(5) As NXOpen.Tag

        Try
            theUFSession.Tabnot.AskNthRow(myPList, calloutID, rowTag)
            theUFSession.Tabnot.AskNthColumn(myPList, 2, colTag)
            theUFSession.Tabnot.AskCellAtRowCol(rowTag, colTag, theCell)

        Catch ex As Exception
            Echo(ex.Message & " | Error thrown in get table info")
        End Try

        Return Nothing
    End Function

    Public Function GetUnloadOption(ByVal dummy As String) As Integer

        Return Session.LibraryUnloadOption.Immediately

    End Function
    Function SelectAnObject(ByVal prompt As String, ByRef selObj As NXObject, objectTypeID As Integer, Optional title As String = "") As Selection.Response
        Dim theUI As UI = UI.GetUI
        Dim includeFeatures As Boolean = True
        Dim keepHighlighted As Boolean = False
        Dim selAction As Selection.SelectionAction = Selection.SelectionAction.ClearAndEnableSpecific
        Dim cursor As Point3d
        Dim scope As Selection.SelectionScope = Selection.SelectionScope.AnyInAssembly
        Dim selectionMask_array(0) As Selection.MaskTriple

        With selectionMask_array(0)
            .Type = objectTypeID
            .Subtype = 0
        End With

        Dim resp As Selection.Response = theUI.SelectionManager.SelectTaggedObject(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
End Module
 
Replies continue below

Recommended for you

I don't see anything obvious that would cause the issue you describe. I'd suggest adding a model update to the end of your code, that might be all that is required.

Code:
Dim markId1 As NXOpen.Session.UndoMarkId = Nothing
markId1 = theSession.SetUndoMark(NXOpen.Session.MarkVisibility.Invisible, "Do update")

'do something

Dim nErrs1 As Integer = Nothing
nErrs1 = theSession.UpdateManager.DoUpdate(markId1)

www.nxjournaling.com
 
Status
Not open for further replies.
Back
Top