Public Class RWEI_0001A Shared oTextSave As String = "C:\Users\Public\Documents\iLogicBuffer.txt" Shared oParent_ofParent As String = "" Sub Main() 'Accessing Assembly Components $ https://modthemachine.typepad.com/my_weblog/2009/03/accessing-assembly-components.html Dim oDashes As String = "" Dim iL_NO As String = "BOM-XX WIP" Dim iL_Name As String = "All Occurrences with BOM Structure" Dim iL_FullName As String = "Rule " & iL_NO & ": " & iL_Name Dim oDoc As Document = ThisApplication.ActiveDocument oDelete_ex_Notepad(oTextSave, iL_NO) oHL1 = "FILE REFERENCE TREE RAN FROM: " & oDoc.FullFileName oWrite_HeaderLines(oTextSave, oHL1) oHL2 = iL_FullName oWrite_HeaderLines(oTextSave, oHL2) For i = 1 To Len(iL_FullName) oDashes = oDashes & "-" Next i oWrite_DashLine(oTextSave, oDashes) oHL3 = "" oWrite_HeaderLines(oTextSave, oHL3) ' Get the active assembly. Dim oAsmDoc As AssemblyDocument oAsmDoc = ThisApplication.ActiveDocument oParent_ofParent = oAsmDoc.DisplayName ' Call the function that does the recursion. Call TraverseAssembly(oAsmDoc.ComponentDefinition.Occurrences, 1) Process.Start("Notepad.exe", oTextSave) End Sub Private Sub TraverseAssembly(Occurrences As ComponentOccurrences, Level As Integer) ' Iterate through all of the occurrence in this collection. This ' represents the occurrences at the top level of an assembly. Dim oOcc As ComponentOccurrence Dim oParent_BOM_Structure As String For Each oOcc In Occurrences If oOcc.ReferencedDocumentDescriptor.ReferencedDocument.IsModifiable = True Then ' Print the name of the current occurrence. ' Check to see if this occurrence represents a subassembly ' and recursively call this function to traverse through it. If oOcc.DefinitionDocumentType = kAssemblyDocumentObject Then Call TraverseAssembly(oOcc.SubOccurrences, Level + 1) End If oOccFFN_cw_EXT = oOcc.ReferencedDocumentDescriptor.ReferencedDocument.FullFileName 'cw file extension oOccLFN_cwExt = oFnOccc_LocalName_WExt(iL_NO, oOccFFN_cw_EXT) oOcc_BOM_Structure = oFn_BOM_Structure_Occ(iL_NO, oOcc) 'Start******************* Parent of Parent ****************** '------------------ 'End*************** Parent of Parent ******************* ' oParent = oOcc.ReferencedDocumentDescriptor.ReferencedDocument.FullFileName Try Dim oParentocc As ComponentOccurrence oParentocc = oOcc.ParentOccurrence oParent_BOM_Structure = oFn_BOM_Structure_Occ("",oParentocc) docFile = oParentocc.Definition.Document oParentFFN = System.IO.Path.GetFileNameWithoutExtension(docFile.FullFileName) oParent = System.IO.Path.GetFileName(docFile.FullFileName) Catch oParentFFN = System.IO.Path.GetFileNameWithoutExtension(oOcc.Parent.Document.DisplayName) oParent = System.IO.Path.GetFileName(oOcc.Parent.Document.DisplayName) End Try If Level = 1 Then oParent_BOM_Structure = oFn_OccLevel1_BomStructure() oData_X = oParent_ofParent & " $ " & oParent & " $ " & oOccLFN_cwExt & " $ " & "Level-" & Level & " $ " & oOcc_BOM_Structure ' oData_X = oParent & "$" & oOcc.Name & "$" & "Level-" & Level & "$" & oOcc_BOM_Structure ' oData_X = oOccLFN_cwExt & "$" & oOccFFN_cw_EXT & "$" & oOcc_BOM_Structure & " " & oParent & "$" & oOcc.Name & "$" & "Level-" & Level oWrite_Data(oTextSave, oData_X) End If Next End Sub Function oFnOccc_LocalName_WExt(iL_NO As String, oOccFFN_cw_EXT As String) oName_Sub = "oFnOccc_LocalName_WExt" oTitle = iL_NO & " $ SUB: " & oName_Sub oPos = Len(oOccFFN_cw_EXT) - InStrRev(oOccFFN_cw_EXT, "\", -1) oName_Local_cw_Ext = Right(oOccFFN_cw_EXT, oPos) Return oName_Local_cw_Ext 'Local file name complete with extension End Function Function oFn_BOM_Structure_Occ(iL_NO As String, oCompOcc As ComponentOccurrence) oName_Sub = "oOcc_BOM_Structure" oTitle = iL_NO & " $ SUB: " & oName_Sub ' Dim oOccurrence As ComponentOccurrence BOM_X = oCompOcc.BOMStructure 'oCompOcc.Definition.BOMStructure If BOM_X = BOMStructureEnum.kDefaultBOMStructure Then oOcc_BOM_Structure = "Default" If BOM_X = BOMStructureEnum.kNormalBOMStructure Then oOcc_BOM_Structure = "Normal" If BOM_X = BOMStructureEnum.kReferenceBOMStructure Then oOcc_BOM_Structure = "Reference" If BOM_X = BOMStructureEnum.kPhantomBOMStructure Then oOcc_BOM_Structure = "Phantom" If BOM_X = BOMStructureEnum.kPurchasedBOMStructure Then oOcc_BOM_Structure = "Purchased" If BOM_X = BOMStructureEnum.kInseparableBOMStructure Then oOcc_BOM_Structure = "Inseparable" If BOM_X = BOMStructureEnum.kVariesBOMStructure Then oOcc_BOM_Structure = "Varies" 'oOcc_BOM_Structure = oFnOccc_LocalName_WExt(iL_NO, oFFN_X) & " <- " & oOcc_BOM_Structure & "(BOM STATUS: Default)" Dim BOM_Structure_Return As String = oOcc_BOM_Structure Return BOM_Structure_Return End Function Function GetOccurrenceParent(oOcc As ComponentOccurrence, oOccName As String) Return oOcc.Parent.Document.DisplayName End Function 'Process.Start("Notepad.exe", oTextSave) 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 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_DashLine(oTextSave As String, oDashes As String) oWrite = System.IO.File.AppendText(oTextSave) oWrite.WriteLine(oDashes) oWrite.Flush() oWrite.Close End Sub Function oFn_OccLevel1_BomStructure() Dim doc = ThisDoc.Document oBOM = doc.ComponentDefinition.BOMStructure If oBOM = BOMStructureEnum.kDefaultBOMStructure Then oOcc_BOM_Structure = "Default" If oBOM = BOMStructureEnum.kNormalBOMStructure Then oOcc_BOM_Structure = "Normal" If oBOM = BOMStructureEnum.kReferenceBOMStructure Then oOcc_BOM_Structure = "Reference" If oBOM = BOMStructureEnum.kPhantomBOMStructure Then oOcc_BOM_Structure = "Phantom" If oBOM = BOMStructureEnum.kPurchasedBOMStructure Then oOcc_BOM_Structure = "Purchased" If oBOM = BOMStructureEnum.kInseparableBOMStructure Then oOcc_BOM_Structure = "Inseparable" If oBOM = BOMStructureEnum.kVariesBOMStructure Then oOcc_BOM_Structure = "Varies" Dim BOM_Structure_Return As String = oOcc_BOM_Structure Return BOM_Structure_Return End Function 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 End Class