Sort feature tree by iproperty

Sort feature tree by iproperty

jesserop
Advocate Advocate
923 Views
4 Replies
Message 1 of 5

Sort feature tree by iproperty

jesserop
Advocate
Advocate

Hi,

 

Is it possible to sort the feature tree by iproperty, like "vendor"? 
At this time it is only possible to sort the tree alphabetically.  

0 Likes
Accepted solutions (2)
924 Views
4 Replies
Replies (4)
Message 2 of 5

WCrihfield
Mentor
Mentor
Accepted solution

Hi @jesserop.  What type of document are you talking about having open when you are trying to move things around in the model browser tree here (Drawing, Assembly, or Part)?  In some situations/cases, some browser nodes can not be moved around to anywhere you would like.  In some other cases, you may not exactly be able to move the one you want to another position, but you can move the other nodes around before or after the one you are wanting to move instead.  It can be fairly complicated task at times, especially by code.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 3 of 5

jesserop
Advocate
Advocate

Hi, it's about the feature tree in assembly mode. 
We use a macro (QuickView add-in) to quick place front views in cutting contour drawings. 
This macro sorts in order of the assembly feature tree.

As we sort cutting contours on thickness (we put that in the vendor iproperty), it would be handy to have an easy macro that sorts the feature tree in assembly mode to "vendor"


Think of the alpha sort component mode in assembly, but instead sort it by property instead of name. 

I hope i explained it good enough 🙂 

 

0 Likes
Message 4 of 5

Ralf_Krieg
Advisor
Advisor
Accepted solution

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
0 Likes
Message 5 of 5

jesserop
Advocate
Advocate

Hi, 

 

Works perfectly, thank you very much!!

0 Likes