Continue to Site

Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

  • Congratulations waross on being selected by the Eng-Tips community for having the most helpful posts in the forums last week. Way to Go!

Journal for Sorting Parts List; Not Working on Certain Assemblies.

Status
Not open for further replies.

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.

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
 
 https://files.engineering.com/getfile.aspx?folder=97d96c25-6689-4874-851a-5197371e25fa&file=PListSort.vb
Replies continue below

Recommended for you

Solved my own problem. The assemblies which weren't working had multiple "Parts List" (Type 165, Subtype 11) objects and that was throwing it off. Added an array and a loop to brute force through all possible Parts List objects. Not ideal but it works.
 
I ran into a similar situation a while ago. It seems that even if you have NX set to only use a single parts list, it can create a temporary parts list and my code was trying to process the temp one instead of the real one. Fortunately, the temporary list was always on layer zero, so a simple check would skip it.

Side note, there is a PList.AskTags function that will return the parts list tags in your part. No need to use .CycleObjsInPart. My code ended up similar to that shown below:

Code:
Dim pListTags() As Tag = Nothing
Dim numPartsLists As Integer

theUfSession.Plist.AskTags(pListTags, numPartsLists)

For Each tempTag As Tag In pListTags
    Dim myPlist As Annotations.Table = Utilities.NXObjectManager.Get(tempTag)
    If myPlist.Layer = 0 Then
        Continue For
    Else
        'process parts list object
    End If
Next

www.nxjournaling.com
 
That is a lot simpler than the CycleObjects loop, I had no idea that existed. Thanks!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor