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

Hi @RoyWickrama_RWEI , after a while I think I have found another method for what you were looking for, and it seems quite simple, it is one of your rules to which I have added a small function

Function FindParent(Parent As Document) As String	'Find real parent
	Line1 :
		Dim oBOMStructnumber As String
	    oBOMStructnumber = Parent.ComponentDefinition.BOMStructure

		If oBOMStructnumber = 51971 Then
			Dim parent2 As Document = Parent.ReferencingDocuments.Item(1)
			Parent=parent2
			GoTo Line1
		End If
	Dim ParentName As String = Parent.DisplayName
	Return ParentName
End Function

 with a loop  that returns the value of the real father, the one that is not phantom For each occurrence of the list of materials, I hope you understand and be useful to you, greetings.

 

Final Rule

Public Class RWEI_0007BOM
	Shared oTextSave As String = "C:\Users\Public\Documents\iLogicBuffer.txt"
Sub Main
	'on error resume next
	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 oBOM As BOM
oBOM = ThisApplication.ActiveDocument.ComponentDefinition.BOM

Dim oBOMView As BOMView
oBOMView = oBOM.BOMViews.Item(1)'Accesing to Model data Column


  Call ListItems(oBOMView.BOMRows, 0)
Process.Start("Notepad.exe", oTextSave)
	
End Sub

Sub ListItems(Rows As BOMRowsEnumerator, indent As Integer)
    Dim oBOMRow As BOMRow
    For Each oBOMRow In Rows
  
		Dim oBOMStructnumber As String
	    oBOMStructnumber = oBOMRow.BOMStructure
		Dim  BOM_Structure As String
		If oBOMStructnumber = 51969 Then BOM_Structure = "The Default Structure Type" 
		If oBOMStructnumber = 51974 Then BOM_Structure = "The inseparable Structure Type" 
		If oBOMStructnumber =  51970 Then BOM_Structure = "The normal Structure Type" 
		If oBOMStructnumber = 51971 Then BOM_Structure = "The phantom Structure Type" 
		If oBOMStructnumber =  51973 Then BOM_Structure = "The purchased Structure Type" 
		If oBOMStructnumber = 51972 Then BOM_Structure = "reference Structure Type" 
		If oBOMStructnumber = 51975 Then BOM_Structure = "The Structure Type varies amongst references" 

		Dim oDef As ComponentDefinition
		oDef = oBOMRow.ComponentDefinitions(1)
		Dim oFFN_X  As String
		oFFN_X  = oDef.Document.Displayname
		
		Dim oDocFile As Document
		oDocFile = oDef.Document
		Dim Parent As Document = oDocFile.ReferencingDocuments.Item(1) 'First parent, check that is not phantom
		
		
		Dim RealParent As String = FindParent(Parent) 'Real parent is not phantom

		
	    If Not oBOMRow.ChildRows Is Nothing Then
	        Call ListItems(oBOMRow.ChildRows, indent + 1)
	    End If
	   	oName_Parent = RealParent & "@" & BOM_Structure & "@" & oFFN_X
		oWrite_Data(oTextSave, oName_Parent)
    Next

End Sub
  
 
Function FindParent(Parent As Document) As String	'Find real parent
	Line1 :
		Dim oBOMStructnumber As String
	    oBOMStructnumber = Parent.ComponentDefinition.BOMStructure

		If oBOMStructnumber = 51971 Then
			Dim parent2 As Document = Parent.ReferencingDocuments.Item(1)
			Parent=parent2
			GoTo Line1
		End If
	Dim ParentName As String = Parent.DisplayName
	Return ParentName
End Function
  
	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
	
End Class

 Please check it, Regards!!


Please accept as solution and give likes if applicable.

I am attaching my Upwork profile for specific queries.

Sergio Daniel Suarez
Mechanical Designer

| Upwork Profile | LinkedIn