To Retrieve Parent, Parent of Parent etc for phantom sub-assemblies

To Retrieve Parent, Parent of Parent etc for phantom sub-assemblies

RoyWickrama_RWEI
Advisor Advisor
2,030 Views
10 Replies
Message 1 of 11

To Retrieve Parent, Parent of Parent etc for phantom sub-assemblies

RoyWickrama_RWEI
Advisor
Advisor

I am developing a rule shown below to extract all the data required for the product documentation in huge assembly environment (couple of thousand drawings).

 

The rule has following functionalities:

  • reference documents (parts and assemblies) excluded
  • phantom parts excluded
  • phantom assemblies excluded

However, I still have a problem connected with some parts reside in one or multiple phantom parents. If the parent of a document (part) is of phantom BOM structure, the true parent of the document is the parent of parent and so on until the parent of normal BOM structure is hit.

 

From my side, if I know the parent of parent, I can get around this issue (at the bottom of this rule). But, it looks like a lot to do!

Could you help, please. Thanks.

 

Public Class RWEI_0010BOM
	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 = "0010-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("Unnamed")'Accesing to Model data Column
'In English__"Unnamed"_"Structured"_"Parts Only"__In Spanish__"Sin nombre"_"Estructurado"_"Solo piezas"

  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 oDef As ComponentDefinition
			oDef = oBOMRow.ComponentDefinitions(1)
			Dim oLFN  As String
			oLFN  = oDef.Document.Displayname
			
			Dim oDocFile As Document
			oDocFile = oDef.Document
			
			If oDocFile.IsModifiable = True Then 
				Dim oBOMStructnumber As String
			    oBOMStructnumber = oBOMRow.BOMStructure
				Dim BOM_Structure As String
				If oBOMStructnumber <> 51972 Then
				
				If oBOMStructnumber = 51969 Then BOM_Structure = "Default" 
				If oBOMStructnumber = 51974 Then BOM_Structure = "Inseparable" 
				If oBOMStructnumber =  51970 Then BOM_Structure = "Normal" 
				If oBOMStructnumber = 51971 Then BOM_Structure = "Phantom" 
				If oBOMStructnumber =  51973 Then BOM_Structure = "Purchased" 
				If oBOMStructnumber = 51972 Then BOM_Structure = "Reference" 
				If oBOMStructnumber = 51975 Then BOM_Structure = "The Structure Type varies amongst references" 
			
	'			Dim oDocFile As Document
	'			oDocFile = oDef.Document
				
	'			If oDocFile.IsModifiable = True Then 
				Dim Parent As Document = oDocFile.ReferencingDocuments.Item(1)
				
				    If Not oBOMRow.ChildRows Is Nothing Then
				        Call ListItems(oBOMRow.ChildRows, indent + 1)
				    End If
					
					Dim oPhantomPart_ParentOfPhantomPart As String = ""
					
					If Right(oLFN, 3) = "ipt" And BOM_Structure = "Phantom" Then
						'Do nothing
					Else
						If Right(oLFN, 3) = "iam" And BOM_Structure = "Phantom" Then
							'Do nothing
						Else If Right(oLFN, 3 = "ipt" And BOM_Structure = "Phantom" Then
'oPhantomPart_ParentOfPhantomPart = oLFN & "$" & Parent.DisplayName Else oName_Parent = Parent.DisplayName & "$" & BOM_Structure & "$" & oLFN oWrite_Data(oTextSave, oName_Parent) End If End If End If End If Next 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 End Class

 

 

 

 

0 Likes
Accepted solutions (1)
2,031 Views
10 Replies
Replies (10)
Message 2 of 11

chandra.shekar.g
Autodesk Support
Autodesk Support

@RoyWickrama_RWEI ,

 

Sorry for delay response,

 

Could you please explain "parent of parent" with examples? It seems that attachments are missing.

 

Please provide sample files to investigate and make sure that files are non confidential.

 

Thanks and regards,


CHANDRA SHEKAR G
Developer Advocate
Autodesk Developer Network



Message 3 of 11

RoyWickrama_RWEI
Advisor
Advisor

Thanks for you are back.

Currently, I am working on it and it is getting better.

I may need further help and I will let you.

Thanks for the reply.

0 Likes
Message 4 of 11

RoyWickrama_RWEI
Advisor
Advisor

Hi Chadra Shekar;

 

I have a rule that scan through all the occurrences. I need to filter library parts.

 

2019-02-27 2332.png

 

I tried with the following:

Dim openDoc As Document
openDoc = ThisDoc.Document
Dim oDoc As Document

If oOcc.IsModifiable = True Then 
	'----------------
	'-----------------
End If

It does not work for occurrences.

I request you to help. Thanks.

 

0 Likes
Message 5 of 11

chandra.shekar.g
Autodesk Support
Autodesk Support
Accepted solution

@RoyWickrama_RWEI ,

 

Try this

 

If oOcc.ReferencedDocumentDescriptor.ReferencedDocument.IsModifiable = False Then
	'It is library document
End If

Thanks and regards,


CHANDRA SHEKAR G
Developer Advocate
Autodesk Developer Network



Message 6 of 11

RoyWickrama_RWEI
Advisor
Advisor

Hi Chandra Shekar;

 

In the interest of determining the parent of a standard part:

  1. if the parent is phantom, the true parent is the parent of the phantom parent. It is fine if the parent of parent is not phantom. I am OK up to this level.
  2. unfortunately, if the parent of parent is phantom, to find the parent of the standard part under consideration, I need to find the parent of parent of parent! This is where I need help. Rule and fake-sample assembly are attached here to. Could you help me to get this around.

In the sample, p0026 has sa0017, sa0012. Now, it is hard to decide the parent of each occurrences. To get this around (generally speaking, in case the parent's BOM structure is phantom), I would like to find:

  • parent of parent

2019-02-28 2247.png

 

2019-02-28 2254.png

 

I keep trying. Not sure will succeed. Please help.

Thanks.

0 Likes
Message 7 of 11

chandra.shekar.g
Autodesk Support
Autodesk Support

@RoyWickrama_RWEI,

 

Hoping that below iLogic code may be helpful.

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 = "Parent of Parent" & "$" & oParent_ofParent & oParent & "$" & oOccLFN_cwExt & "$" & oOcc.Name & "$" & "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

Result of above iLogic code

FILE REFERENCE TREE RAN FROM: D:\Chandra\Autodesk Cases\Inventor\Mar-2019\15098877\LAF Parents\LAF iLogic API and Forum\SBS-LAF-sa0013.iam
Rule BOM-XX WIP: All Occurrences with BOM Structure
---------------------------------------------------

Parent of Parent$SBS-LAF-sa0013.iamSBS-LAF-sa0011.iam$SBS-LAF-p0024.ipt$SBS-LAF-p0024:1$Level-2$Normal
Parent of Parent$SBS-LAF-sa0013.iamSBS-LAF-sa0011.iam$SBS-LAF-p0026.ipt$SBS-LAF-p0026:1$Level-2$Normal
Parent of Parent$SBS-LAF-sa0013.iamSBS-LAF-sa0011.iam$SBS-LAF-p0025.ipt$SBS-LAF-p0025:1$Level-2$Phantom
Parent of Parent$SBS-LAF-sa0013.iamSBS-LAF-sa0011.iam$SBS-LAF-p0032.ipt$SBS-LAF-p0032:1$Level-2$Reference
Parent of Parent$SBS-LAF-sa0013.iamSBS-LAF-sa0013.iam$SBS-LAF-sa0011.iam$SBS-LAF-sa0011:1$Level-1$Normal
Parent of Parent$SBS-LAF-sa0013.iamSBS-LAF-sa0012.iam$SBS-LAF-p0024.ipt$SBS-LAF-p0024:1$Level-2$Normal
Parent of Parent$SBS-LAF-sa0013.iamSBS-LAF-sa0012.iam$SBS-LAF-p0026.ipt$SBS-LAF-p0026:1$Level-2$Reference
Parent of Parent$SBS-LAF-sa0013.iamSBS-LAF-sa0012.iam$SBS-LAF-p0025.ipt$SBS-LAF-p0025:1$Level-2$Phantom
Parent of Parent$SBS-LAF-sa0013.iamSBS-LAF-sa0017.iam$SBS-LAF-p0024.ipt$SBS-LAF-p0024:1$Level-3$Normal
Parent of Parent$SBS-LAF-sa0013.iamSBS-LAF-sa0017.iam$SBS-LAF-p0026.ipt$SBS-LAF-p0026:1$Level-3$Normal
Parent of Parent$SBS-LAF-sa0013.iamSBS-LAF-sa0017.iam$SBS-LAF-p0026.ipt$SBS-LAF-p0026:2$Level-3$Normal
Parent of Parent$SBS-LAF-sa0013.iamSBS-LAF-sa0012.iam$SBS-LAF-sa0017.iam$SBS-LAF-sa0017:1$Level-2$Phantom
Parent of Parent$SBS-LAF-sa0013.iamSBS-LAF-sa0013.iam$SBS-LAF-sa0012.iam$SBS-LAF-sa0012:1$Level-1$Phantom
Parent of Parent$SBS-LAF-sa0013.iamSBS-LAF-sa0013.iam$SBS-LAF-p0024.ipt$SBS-LAF-p0024:1$Level-1$Normal
Parent of Parent$SBS-LAF-sa0013.iamSBS-LAF-sa0011.iam$SBS-LAF-p0024.ipt$SBS-LAF-p0024:1$Level-2$Normal
Parent of Parent$SBS-LAF-sa0013.iamSBS-LAF-sa0011.iam$SBS-LAF-p0026.ipt$SBS-LAF-p0026:1$Level-2$Normal
Parent of Parent$SBS-LAF-sa0013.iamSBS-LAF-sa0011.iam$SBS-LAF-p0025.ipt$SBS-LAF-p0025:1$Level-2$Phantom
Parent of Parent$SBS-LAF-sa0013.iamSBS-LAF-sa0011.iam$SBS-LAF-p0032.ipt$SBS-LAF-p0032:1$Level-2$Reference
Parent of Parent$SBS-LAF-sa0013.iamSBS-LAF-sa0013.iam$SBS-LAF-sa0011.iam$SBS-LAF-sa0011:2$Level-1$Normal
Parent of Parent$SBS-LAF-sa0013.iamSBS-LAF-sa0018.iam$SBS-LAF-p0024.ipt$SBS-LAF-p0024:1$Level-2$Normal
Parent of Parent$SBS-LAF-sa0013.iamSBS-LAF-sa0017.iam$SBS-LAF-p0024.ipt$SBS-LAF-p0024:1$Level-3$Normal
Parent of Parent$SBS-LAF-sa0013.iamSBS-LAF-sa0017.iam$SBS-LAF-p0026.ipt$SBS-LAF-p0026:1$Level-3$Normal
Parent of Parent$SBS-LAF-sa0013.iamSBS-LAF-sa0017.iam$SBS-LAF-p0026.ipt$SBS-LAF-p0026:2$Level-3$Normal
Parent of Parent$SBS-LAF-sa0013.iamSBS-LAF-sa0018.iam$SBS-LAF-sa0017.iam$SBS-LAF-sa0017:1$Level-2$Phantom
Parent of Parent$SBS-LAF-sa0013.iamSBS-LAF-sa0013.iam$SBS-LAF-sa0018.iam$SBS-LAF-sa0018:1$Level-1$Phantom
Parent of Parent$SBS-LAF-sa0013.iamSBS-LAF-sa0019.iam$SBS-LAF-p0024.ipt$SBS-LAF-p0024:1$Level-2$Normal
Parent of Parent$SBS-LAF-sa0013.iamSBS-LAF-sa0012.iam$SBS-LAF-p0024.ipt$SBS-LAF-p0024:1$Level-3$Normal
Parent of Parent$SBS-LAF-sa0013.iamSBS-LAF-sa0012.iam$SBS-LAF-p0026.ipt$SBS-LAF-p0026:1$Level-3$Reference
Parent of Parent$SBS-LAF-sa0013.iamSBS-LAF-sa0012.iam$SBS-LAF-p0025.ipt$SBS-LAF-p0025:1$Level-3$Phantom
Parent of Parent$SBS-LAF-sa0013.iamSBS-LAF-sa0017.iam$SBS-LAF-p0024.ipt$SBS-LAF-p0024:1$Level-4$Normal
Parent of Parent$SBS-LAF-sa0013.iamSBS-LAF-sa0017.iam$SBS-LAF-p0026.ipt$SBS-LAF-p0026:1$Level-4$Normal
Parent of Parent$SBS-LAF-sa0013.iamSBS-LAF-sa0017.iam$SBS-LAF-p0026.ipt$SBS-LAF-p0026:2$Level-4$Normal
Parent of Parent$SBS-LAF-sa0013.iamSBS-LAF-sa0012.iam$SBS-LAF-sa0017.iam$SBS-LAF-sa0017:1$Level-3$Phantom
Parent of Parent$SBS-LAF-sa0013.iamSBS-LAF-sa0019.iam$SBS-LAF-sa0012.iam$SBS-LAF-sa0012:1$Level-2$Phantom
Parent of Parent$SBS-LAF-sa0013.iamSBS-LAF-sa0013.iam$SBS-LAF-sa0019.iam$SBS-LAF-sa0019:1$Level-1$Normal
Parent of Parent$SBS-LAF-sa0013.iamSBS-LAF-sa0020.iam$SBS-LAF-p0026.ipt$SBS-LAF-p0026:1$Level-2$Reference
Parent of Parent$SBS-LAF-sa0013.iamSBS-LAF-sa0012.iam$SBS-LAF-p0024.ipt$SBS-LAF-p0024:1$Level-3$Normal
Parent of Parent$SBS-LAF-sa0013.iamSBS-LAF-sa0012.iam$SBS-LAF-p0026.ipt$SBS-LAF-p0026:1$Level-3$Reference
Parent of Parent$SBS-LAF-sa0013.iamSBS-LAF-sa0012.iam$SBS-LAF-p0025.ipt$SBS-LAF-p0025:1$Level-3$Phantom
Parent of Parent$SBS-LAF-sa0013.iamSBS-LAF-sa0017.iam$SBS-LAF-p0024.ipt$SBS-LAF-p0024:1$Level-4$Normal
Parent of Parent$SBS-LAF-sa0013.iamSBS-LAF-sa0017.iam$SBS-LAF-p0026.ipt$SBS-LAF-p0026:1$Level-4$Normal
Parent of Parent$SBS-LAF-sa0013.iamSBS-LAF-sa0017.iam$SBS-LAF-p0026.ipt$SBS-LAF-p0026:2$Level-4$Normal
Parent of Parent$SBS-LAF-sa0013.iamSBS-LAF-sa0012.iam$SBS-LAF-sa0017.iam$SBS-LAF-sa0017:1$Level-3$Phantom
Parent of Parent$SBS-LAF-sa0013.iamSBS-LAF-sa0020.iam$SBS-LAF-sa0012.iam$SBS-LAF-sa0012:1$Level-2$Phantom
Parent of Parent$SBS-LAF-sa0013.iamSBS-LAF-sa0013.iam$SBS-LAF-sa0020.iam$SBS-LAF-sa0020:1$Level-1$Normal
Parent of Parent$SBS-LAF-sa0013.iamSBS-LAF-sa0013.iam$SBS-LAF-p0026.ipt$SBS-LAF-p0026:1$Level-1$Reference

Thanks and regards,


CHANDRA SHEKAR G
Developer Advocate
Autodesk Developer Network



Message 8 of 11

RoyWickrama_RWEI
Advisor
Advisor

Thanks for the reply.

A find the parents are the same for all the occurrences.

I attached a simple fake-model  and the code revised to output what we are looking at.

 

Could you take a look at, please. Thanks.

 

Inventor Professional - 20182019-03-01 08_2001.png

 

 

 

 

0 Likes
Message 9 of 11

RoyWickrama_RWEI
Advisor
Advisor

Hi Chandra Shekar;

It is kind of tricky. I spent my whole week (without giving up) to get this around, because I really need it.

Finally, my new thinking ended with success.

Thanks you for your help: your help incorporated throughout.

 

 

0 Likes
Message 10 of 11

chandra.shekar.g
Autodesk Support
Autodesk Support

@RoyWickrama_RWEI ,

 

Thanks for letting me know that you have found a solution for issue.

 

Thanks and regards,


CHANDRA SHEKAR G
Developer Advocate
Autodesk Developer Network



0 Likes
Message 11 of 11

Sergio.D.Suárez
Mentor
Mentor

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