Option Explicit On Imports System.IO Imports Path = System.IO.Path Sub Main() Dim doc = ThisDoc.Document If String.IsNullOrEmpty(doc.FullFileName) Then Throw New InvalidOperationException("The document must be saved before running this rule") End If Dim reportFileName = Path.Combine(Path.GetDirectoryName(doc.FullFileName), Path.GetFileNameWithoutExtension(doc.FullFileName) + "_unresolved.txt") Logger.Info("Report file : {0}", reportFileName) _unresolvedNames.Clear() CheckBrowserPanes(ThisDoc.Document) Using reportWriter As StreamWriter = New StreamWriter(reportFileName) Dim fullName = ThisDoc.Document.FullDocumentName If _unresolvedNames.Count = 0 Then reportWriter.WriteLine("The document {0} contains no unresolved components.", fullName) Else If _unresolvedNames.Count = 1 Then reportWriter.WriteLine("The document {0} contains {1} unresolved file as a component. Unresolved document name:", fullName, _unresolvedNames.Count) Else reportWriter.WriteLine("The document {0} contains {1} unresolved files as components. Unresolved document names:", fullName, _unresolvedNames.Count) End If For Each name As String In _unresolvedNames.Keys reportWriter.WriteLine(name) Next End If End Using End Sub Private _unresolvedNames As New Dictionary(Of String, Integer) ' dictionaryof document name -> unresolved component count Sub CheckBrowserPanes(doc As Document) 'Logger.Debug("-- Doc " & doc.DisplayName) For Each pane As BrowserPane In doc.BrowserPanes If (pane.InternalName = "AmBrowserArrangement" Or pane.InternalName.Contains("PmDefault")) Then 'Logger.Debug(" ------------------------- ") 'Logger.Debug("--- pane: {0}: {1} : ({2})", pane.Name, pane.InternalName, pane.GetHashCode()) Dim rootNode As Inventor.BrowserNode rootNode = pane.TopNode Dim node As Inventor.BrowserNode For Each node In rootNode.BrowserNodes CheckNode(node, vbTab) Next End If Next End Sub Sub CheckNode(node As Inventor.BrowserNode, prefix As String) Dim def = node.BrowserNodeDefinition ' Logger.Debug("{0} --- Node: {1} : ({2})", prefix, def.Label, node.FullPath) Dim nativeDef = TryCast(def, NativeBrowserNodeDefinition) If nativeDef IsNot Nothing Then Dim type As ObjectTypeEnum = ObjectTypeEnum.kUnknownObject Try type = nativeDef.NativeObject.Type Catch End Try If type = ObjectTypeEnum.kComponentOccurrenceObject Then If def.StateIconToolTipText = "Unresolved" Then Logger.Warn("--- Unresolved : {0}", def.Label) Dim compOcc As ComponentOccurrence = nativeDef.NativeObject Dim fullName = compOcc.ReferencedDocumentDescriptor.FullDocumentName Dim currentValue As Integer Dim haveEntry As Boolean = _unresolvedNames.TryGetValue(fullName, currentValue) If haveEntry Then _unresolvedNames(fullName) = currentValue + 1 Else _unresolvedNames(fullName) = 1 End If End If End If End If For Each subNode As Inventor.BrowserNode In node.BrowserNodes CheckNode(subNode, prefix + vbTab) Next End Sub