12-27-2021
07:16 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
12-27-2021
07:16 AM
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:
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.
Blog: hjalte.nl - github.com