LHolm
Industrial
- Feb 17, 2020
- 6
I recently wrote a Journal to search through the current work part for the Parts List, add a column for the Layer Number, sort by that column, update, then delete that column.
It worked for a while, but I've started running into issues with some assemblies where the journal does not run properly.
No errors pop up, and the journal runs to completion, but it doesn't actually add the column to the parts list, nor does it sort the list like it should.
I haven't been able to narrow down what is different between the assemblies in which the journal fails and the assemblies in which the journal works. If anyone can spot anything glaring in the following code that might explain this discrepancy, I would appreciate it.
It worked for a while, but I've started running into issues with some assemblies where the journal does not run properly.
No errors pop up, and the journal runs to completion, but it doesn't actually add the column to the parts list, nor does it sort the list like it should.
I haven't been able to narrow down what is different between the assemblies in which the journal fails and the assemblies in which the journal works. If anyone can spot anything glaring in the following code that might explain this discrepancy, I would appreciate it.
Code:
' LOUIS HOLM
' 02/11/2020
' RED BUD INDUSTRIES
Imports System
Imports NXOpen
Imports NXOpenUI
Imports NXOpen.UF
Imports NXOpen.Selection
Imports NXOpen.Annotations
Module NXJournal
Sub Main (ByVal args() As String)
Dim varSession As Session = Session.GetSession()
Dim varPart As Part = varSession.Parts.Work
Dim varDrawingSheet = varPart.DrawingSheets.CurrentDrawingSheet
Dim UFS As NXOpen.UF.UFSession = NXOpen.UF.UFSession.GetUFSession
Dim tagPart As NXOpen.Tag = varPart.Tag
Dim i As Integer
Dim tagTable
Dim varUI As UI = UI.GetUI
Dim USM = varUI.SelectionManager
Dim tagTabNote
Dim varColPrefs
Dim datSort
Dim tagTempCol
Dim tagCol
Dim intNumCol
Dim blnObjectCycleComplete = False
Dim tempTagNote
Dim intT
Dim intST
' FIND THE PARTS LIST
While blnObjectCycleComplete = False
UFS.Obj.CycleObjsInPart(tagPart, 165, tempTagNote)
If tempTagNote = NXOpen.Tag.Null Then
blnObjectCycleComplete = True
Else
UFS.Obj.AskTypeAndSubtype(tempTagNote, intT, intST)
If intST = 11
tagTabNote = tempTagNote
blnObjectCycleComplete = True
End If
End If
End While
' ADD COLUMN
UFS.Plist.AskDefaultColPrefs(varColPrefs)
varColPrefs.default_string = "<W$=@$LAYER>"
UFS.Plist.CreateColumn(0.5, varColPrefs, 0, tagCol)
UFS.TabNot.AddColumn(tagTabNote, tagCol, 0)
' SORT BY NEW COLUMN
UFS.TabNot.AskNmColumns(tagTabNote, intNumCol)
For i = 0 to intNumCol-1
UFS.TabNot.AskNthColumn(tagTabNote, i, tagTempCol)
UFS.TabNot.AskColumnSortData(tagTempCol, datSort)
datSort.sort_index = 0
UFS.TabNot.SetColumnSortData(tagTempCol, datSort)
Next i
UFS.TabNot.AskColumnSortData(tagCol, datSort)
datSort.sort_index = 1
datSort.sort_direction = 0
UFS.TabNot.SetColumnSortData(tagCol, datSort)
' UPDATE PARTS LIST AND DELETE COLUMN
UFS.TabNot.Update(tagTabNote)
UFS.TabNot.RemoveColumn(tagCol)
End Sub
End Module