Announcements
Attention for Customers without Multi-Factor Authentication or Single Sign-On - OTP Verification rolls out April 2025. Read all about it here.

I'm not sure what you think is too slow or what you have now. the following rule will find everything 10 times. on average it takes 300 milliseconds to find 1000+ occurrences. I think that is reasonable. My output in the log:

JelteDeJong_0-1640618099099.png

Public Sub Main()

    Dim doc As AssemblyDocument = ThisDoc.Document
    Dim topNode = doc.BrowserPanes.Item("Model").TopNode

    Dim Stopwatch As New Stopwatch()
    
	
	Dim tries = 10
	Dim totalTime As Double = 0
	Dim nodesCount = 0
	
	For i = 1 To tries
		Stopwatch.Reset()
		Stopwatch.Start()
		
		' This line does all the work
		Dim nodes = GetModelsRecursive(topNode)
		
		Stopwatch.Stop()
    	Dim ts = Stopwatch.Elapsed
		totalTime = totalTime + ts.Milliseconds
		nodesCount = nodes.Count
		Logger.Info("RunTime " & i & ": " &  ts.Milliseconds)
	Next
	
    Logger.Info("RunTime mean: " & (totalTime/tries))
	Logger.Info("Occurences found: " & nodesCount)

End Sub

Public Function GetModelsRecursive(node As BrowserNode) As List(Of BrowserNode)
    Dim nodes As New List(Of BrowserNode)

    For Each subNode As BrowserNode In node.BrowserNodes
        Try
            If (TypeOf subNode.NativeObject Is ComponentOccurrence) Then
                nodes.Add(subNode)
                nodes.AddRange(GetModelsRecursive(subNode))
            End If
            If (TypeOf subNode.NativeObject Is OccurrencePattern) Then
                nodes.AddRange(GetModelsRecursive(subNode))
            End If
            If (TypeOf subNode.NativeObject Is OccurrencePatternElement) Then
                nodes.AddRange(GetModelsRecursive(subNode))
            End If
        Catch ex As Exception
        End Try
    Next
    Return nodes
End Function

 

Jelte de Jong
Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.

EESignature


Blog: hjalte.nl - github.com