Hello
The ordering of this tree is not a single line of code. There is no SortByXYZ command. A quick'n dirty hack. No guarantee this works all times. If Vendor is empty, code handles it as if it is 0. If Vendor is the same for multiple BrowserNodes, the nodes will sorted in alphabetical order.
Class ThisRule
Private Sub Main()
Dim oAssDoc As AssemblyDocument=ThisDoc.Document
Dim oOccs As ComponentOccurrences= oAssDoc.ComponentDefinition.Occurrences
Dim BNodes As New List(Of BNode)
Dim oBP As BrowserPane
For Each oBP In oAssDoc.BrowserPanes
If oBP.Name = "Model" Then Exit For
Next
If oBP Is Nothing Then Exit Sub
Dim oBNode As Inventor.BrowserNode
Dim oCompOcc As Inventor.ComponentOccurrence
Dim oDoc As Inventor.Document
Dim dValue As Double
For Each oBNode In oBP.TopNode.BrowserNodes
If Not oBNode.NativeObject Is Nothing Then
If oBNode.NativeObject.Type = kComponentOccurrenceObject Then
oCompOcc = oBNode.NativeObject
oDoc = oCompOcc.Definition.Document
Try
dValue = CDbl(oDoc.PropertySets("{32853F0F-3444-11D1-9E93-0060B03C1CA6}").Item("Vendor").Value)
Catch
dValue = 0
End Try
BNodes.Add(New BNode With {.Vendor=dValue,.Occ=oCompOcc})
End If
End If
Next
BNodes.Sort
Dim oLastNode As BrowserNode = oBP.TopNode.BrowserNodes(7)
For Each thisNode As BNode In BNodes
oBNode = oBP.GetBrowserNodeFromObject(thisNode.Occ)
oBP.Reorder(oLastNode, False, oBNode)
oLastNode=oBNode
Next
End Sub
End Class
Public Class BNode
Implements IComparable(Of BNode)
Public Property Vendor As Double
Public Property Occ As Inventor.ComponentOccurrence
Public Function CompareTo(ByVal other As BNode) As Integer _
Implements System.IComparable(Of BNode).CompareTo
' Compare the Vendor value
Dim compare As Integer
compare = Me.Vendor.CompareTo(other.Vendor)
' If the Vendor values are the same, compare the Occurrence names.
If compare = 0 Then
compare = Me.Occ.Name.CompareTo(other.Occ.Name)
End If
Return compare
End Function
End Class
R. Krieg
RKW Solutions
www.rkw-solutions.com