Imports System.Windows.Forms Public Class RWEI_0007BOM Shared oTextSave As String = "C:\Users\Public\Documents\iLogicBuffer.txt" Sub Main Dim oAssy_ThisDoc As AssemblyDocument Dim oDoc As Document = ThisApplication.ActiveDocument Dim iL_NO As String = "0002-BOM" oDelete_ex_Notepad(oTextSave, iL_NO) Dim HL1_Prefix As String = "FILE REFERENCE TREE RAN FROM: " oHL1 = HL1_Prefix & oDoc.FullFileName oWrite_HeaderLines(oTextSave, oHL1) Dim iL_Name As String = "All Occurrences with BOM Structure" Dim oHL2 As String = "Rule " & iL_NO & ": " & iL_Name oWrite_HeaderLines(oTextSave, oHL2) Dim oDashes As String = "" For i = 1 To Len(oHL2) oDashes = oDashes & "-" Next i Dim oHL3 As String = oDashes oWrite_HeaderLines(oTextSave, oHL3) Dim oHL4 As String = "" oWrite_HeaderLines(oTextSave, oHL4) Dim oName_Parent As String Dim oAsmCompDef As AssemblyComponentDefinition oAsmCompDef = ThisApplication.ActiveDocument.ComponentDefinition 'Iterate through all of the occurrences Dim oOccurrence As ComponentOccurrence For Each oOccurrence In oAsmCompDef.Occurrences Call ProcessAllChildren(iL_NO, oOccurrence, oName_Parent) Next Process.Start("Notepad.exe", oTextSave) End Sub Public Sub ProcessAllChildren(iL_NO As String, oOccurrence As ComponentOccurrence, oName_Parent As String) oName_Parent = System.IO.Path.GetFileNameWithoutExtension(oOccurrence.Parent.Document.DisplayName) oName_Parent = oName_Parent & "@" & Func_BOM_Structure(iL_NO, oOccurrence) oWrite_Data(oTextSave, oName_Parent) Dim oCompOcc As ComponentOccurrence Dim oComponentSubOccurrences As ComponentOccurrences ' Process sub-assemblies ' End of Process sub-assemblies End Sub Sub oWrite_HeaderLines(oTextSave As String, oHeaderLine As String) oWrite = System.IO.File.AppendText(oTextSave) oWrite.WriteLine(oHeaderLine) oWrite.Flush() oWrite.Close End Sub Sub oWrite_Data(oTextSave As String, oData As String) oWrite = System.IO.File.AppendText(oTextSave) oWrite.WriteLine(oData) oWrite.Flush() oWrite.Close End Sub Sub oDelete_ex_Notepad(oTextSave As String, iL_NO As String) 'To delete oTextSave if existing. If System.IO.File.Exists(oTextSave) = True Then System.IO.File.Delete(oTextSave) End If End Sub Function oParent_Function(oOccurrenceX As Object) Dim oAsmCompDef As AssemblyComponentDefinition oAsmCompDef = ThisApplication.ActiveDocument.ComponentDefinition Dim oParentX As String = System.IO.Path.GetFileNameWithoutExtension(oOccurrenceX.Parent.Document.DisplayName) MessageBox.Show("oOccurrence: " & oOccurrenceX.name _ & vbLf & "PARENT: " & oParentX, "Title") Return oParentX End Function Function oLocalDocNameWExt(oName As String) oPos = Len(oName) - InStrRev(oName, "\", -1) oNameWExt = Right(oName, oPos) Return oNameWExt End Function Function Func_BOM_Structure(iL_NO As String, oCompOcc As ComponentOccurrence) oName_Sub = "BOM_Structure" oTitle = iL_NO & " @ SUB: " & oName_Sub Dim oOccurrence As ComponentOccurrence oFFN_X = oCompOcc.ReferencedDocumentDescriptor.ReferencedDocument.FullFileName BOM_X = oCompOcc.Definition.BOMStructure If BOM_X = BOMStructureEnum.kDefaultBOMStructure Then BOM_Structure = "Default" If BOM_X = BOMStructureEnum.kNormalBOMStructure Then BOM_Structure = "Normal" If BOM_X = BOMStructureEnum.kPhantomBOMStructure Then BOM_Structure = "Phantom" If BOM_X = BOMStructureEnum.kReferenceBOMStructure Then BOM_Structure = "Reference" If BOM_X = BOMStructureEnum.kPurchasedBOMStructure Then BOM_Structure = "Purchased" If BOM_X = BOMStructureEnum.kInseparableBOMStructure Then BOM_Structure = "Inseparable" If BOM_X = BOMStructureEnum.kVariesBOMStructure Then BOM_Structure = "Varies" Dim BOM_Structure_Return As String = BOM_Structure & "@" & oFFN_X Return BOM_Structure_Return End Function Function oDoc_LocalName_WExt(iL_NO As String, oFFN_cw_EXT As String) oName_Sub = "oDoc_LocalName_WExt" oTitle = iL_NO & " @ SUB: " & oName_Sub oPos = Len(oFFN_cw_EXT) - InStrRev(oFFN_cw_EXT, "\", -1) oName_Local_cw_Ext = Right(oFFN_cw_EXT, oPos) Return oName_Local_cw_Ext 'Local file name complete with extension End Function End Class