Community
Inventor Programming - iLogic, Macros, AddIns & Apprentice
Inventor iLogic, Macros, AddIns & Apprentice Forum. Share your knowledge, ask questions, and explore popular Inventor topics related to programming, creating add-ins, macros, working with the API or creating iLogic tools.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Retrieve File Name (Local), BOM Structure, File Name (Full) for all Occurrences

11 REPLIES 11
SOLVED
Reply
Message 1 of 12
RoyWickrama_RWEI
1940 Views, 11 Replies

Retrieve File Name (Local), BOM Structure, File Name (Full) for all Occurrences

I keep developing a rule to retrieve following data (recorded in a notepad document):

  1. Parent (local file name) of occurrence
  2. Bom Structure of the occurrence
  3. Full file name of the occurrence

for each occurrence in the assembly (which is the main erection assembly usually) under consideration.

Data may appear as Parent @ BOM Structure @ Full File Name @ sign is just delimiter.

I still keep doing by myself - Thought getting help because I may not succeed (whatever time I spend).

I request help.

2019-02-17 11_16.png

2019-02-17 1214.png

11 REPLIES 11
Message 2 of 12

Hi, following another statement about recognizing the father of a component, I write another statement, maybe I can help you, I have not checked it completely. It is a question of looking for all the reference files of an assembly and looking for the father of these files (it does not look for occurrences) this is a simple proposal to test it in a small assembly.

Dim openDoc As Document
openDoc = ThisDoc.Document
Dim doc As Document
For Each doc In openDoc.AllReferencedDocuments
Dim Parent As Document = doc.ReferencingDocuments.Item(1)
	BOM_X = Parent.componentdefinition.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" 
	MessageBox.Show(doc.displayname & ": " & Parent.DisplayName & "@" & BOM_Structure, "Title")
Next

Modified for your particular use would be something like this

 

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
	
	Dim doc As Document
		For Each doc In oDoc.AllReferencedDocuments
			oFFN_X =  doc.FullFileName
			Dim Parent As Document = doc.ReferencingDocuments.Item(1)
			BOM_X = Parent.componentdefinition.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" 
			oName_Parent = Parent.DisplayName & "@" & BOM_Structure & "@" & oFFN_X
			oWrite_Data(oTextSave, oName_Parent)
		Next
	Process.Start("Notepad.exe", oTextSave)
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

 I hope it works for you and you can try it. To tell the truth, it is very nice to be able to share ideas with you, I am not an expert or anything like that, I am a simple self-taught person who has learned a lot from your contributions, that is why I feel indebted to you for a long time. 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

Message 3 of 12

I like both of the codes provided. The top one is fine because it gives all the unique documents of the assembly (good for tracking all the drawings to be issued).

Still the first solution (in your 1st posting) you provided is fine because it displays all the occurrences (i.e. what we really see in the assembly) where we can find the quantities and retrieve the BOM structure as well.

 

In this regard, (retrieving the BOM structure) I have an issue. Documents with reference BOM structure assigned in the assembly level, still indicate the default. I am sorry to ask you this, but could you take a kook at this as well?

Thanks.

I need to extract BOM Structure data as well, but I posted that as a separately because I thought go...

2019-02-18 0044.png

 

 

Message 4 of 12

I've checked it. I think the problem is here. The rule shows you the property of the list of materials that is accessed through the document settings, read what I show you below

2.jpg

Now if you change this property from assembly, as I show you next, it will not reflect the change because the change does not do it at the document level, it does it at the assembly level

11.jpg

3.jpg

This may be due to the fact that one could have an assembly that could use it several times, and only one of them is a reference for example (then the property of the assembly document would not be a reference). I suppose then that the structure of the rule is fine in your models (that is, it reads the property correctly only we need to read it from another place), maybe we should access the property from a higher level than the occurrence

What do you think about it?


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

Message 5 of 12

I agree with you.

While I was testing with several sample models, once I saw it the Bom Structure reflecting the BOM assigned in the assembly: I soon lost my work and hard to think what/how was it. I will let you know if I come across with it again.

 

I need it because I can't deduce accurate results from my exported list.

Message 6 of 12

I have not yet been able to solve the whole problem but I have found something that I wanted to share with you. I have accessed the structure of the Bom, from the list of materials "Model data" from the assembly. It's still incomplete but maybe it's a new path. With this method, a piece can be a reference in the assembly and at the same time it can not be a reference in the properties of the document. Then when you load the list you will put it as reference as appropriate.
The initial base code to search for that stretch is this applied to a small assembly

Dim oBOM As BOM
oBOM = ThisApplication.ActiveDocument.ComponentDefinition.BOM
Dim oBOMView As BOMView
oBOMView = oBOM.BOMViews.Item("Unnamed")'Accesing to Model data Column "Unnamed"
Dim oBOMRow As BOMRow

For Each oBOMRow In oBOMView.BOMRows
    'Set a reference to the primary ComponentDefinition of the row
    Dim oBOMStructnumber As String
    oBOMStructnumber = oBOMRow.BOMStructure
	Dim  oBOMStruct As String
	If oBOMStructnumber = 51969 Then oBOMStruct = "The Default Structure Type" 
	If oBOMStructnumber = 51974 Then oBOMStruct = "The inseparable Structure Type" 
	If oBOMStructnumber =  51970 Then oBOMStruct = "The normal Structure Type" 
	If oBOMStructnumber = 51971 Then oBOMStruct = "The phantom Structure Type" 
	If oBOMStructnumber =  51973 Then oBOMStruct = "The purchased Structure Type" 
	If oBOMStructnumber = 51972 Then oBOMStruct = "reference Structure Type" 
	If oBOMStructnumber = 51975 Then oBOMStruct = "The Structure Type varies amongst references" 

	Dim oDef As ComponentDefinition
	oDef = oBOMRow.ComponentDefinitions(1)
	Dim oFileName As String
	oFileName = oDef.Document.Displayname'PropertySets("{32853F0F-3444-11D1-9E93-0060B03C1CA6}")("Part Number").value
	MessageBox.Show(oFileName & "->" & oBOMStruct, "Title")
	
Next

 and accommodating it a bit, but not fulfilling all your goals

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 oBOM As BOM
oBOM = ThisApplication.ActiveDocument.ComponentDefinition.BOM
Dim oBOMView As BOMView
oBOMView = oBOM.BOMViews.Item("Sin nombre")'Accesing to Model data Column
'In English__"Unnamed"_"Structured"_"Parts Only"__In Spanish__"Sin nombre"_"Estructurado"_"Solo piezas"

For Each oBOMRow In oBOMView.BOMRows
    'Set a reference to the primary ComponentDefinition of the row
    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)

	oName_Parent = Parent.DisplayName & "@" & BOM_Structure & "@" & oFFN_X
	oWrite_Data(oTextSave, oName_Parent)
	
Next

	Process.Start("Notepad.exe", oTextSave)
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

 


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

Message 7 of 12

Following with attempts here you have another sample, surely it needs to retouch, but it can be a favorable way, you can place the quantities to each piece or component, you have to keep investigating

 

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 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 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)
		
	    If Not oBOMRow.ChildRows Is Nothing Then
	        Call ListItems(oBOMRow.ChildRows, indent + 1)
	    End If
	   	oName_Parent = Parent.DisplayName & "@" & BOM_Structure & "@" & oFFN_X
		oWrite_Data(oTextSave, oName_Parent)
    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

 


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

Message 8 of 12

This is an excellent solution: able to extract occurrence local file name, BOM structure of occurrence where reference BOM structure at assembly is captured and parent of the occurrence.

 

With this an Excel-Pro can extract all the information required to track the product documentation for manufacturing: good for very large assemblies. (as I am going to do)

 

Thanks to

  • Chandra Shekar
  • Yuvilo
  • Jane Fan
  • Bradeneurope
  • JamieVJonson2
  • the FORUM at large.

 

Roy Wickrama

 

Inventor Professional 2019

Vault Professional 2019

Solidworks Professional 2018

Mathcad Prime 5.0

Message 9 of 12

Attached here to is the revised code (to exclude all content center and library parts):

 

		If oDocFile.IsModifiable = True Then 

 finally;

			   	oName_Parent = Parent.DisplayName & "@" & BOM_Structure & "@" & oFFN_X
				oWrite_Data(oTextSave, oName_Parent)
			End If

All content center and library parts excluded 

Message 10 of 12

Hi Yuvilo;

 

For phantom sub-assemblies need parent, parent of parent, etc until the parent is of non-phantom BOM structure

 

Please don't mind for reverting back to you for help. I further developed the rule to function as shown below:

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

I have some parts with multiple phantom parents and normal parents. If the parent of a document (part) is of phantom BOM structure, the true parent is the parent of parent and so on until the parent the parent of normal BOM structure is hit.

 

From my side, if I know the prent 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

 

 

 

 

Message 11 of 12

Hi Yuvilo;

 

Thanks again for your help. I was using your rule. I also like to dd more functionality in the rule such as:

  1. Total Quantity under each parent
  2. Parent of Parent.

I have some of the assemblies of which the BOM structure is phantom.  In this case the parent of any child in this assembly is the parent of parent.

Could you shed some light to get around this. is the parent of parent. I have been trying a lot of time without success. I attached a fake-sample.

 

I request help. Thanks.

 

Autodesk Inventor 2019

 

Message 12 of 12

  Hi, I have followed your threads about the subject. I've noticed that when it comes to property in phantom, you can use the bill of materials property of the part, you may not have to read it from the property of assembly list model data.
I have found a result but my limitations in programming have not been able to insert it within the rule that you need.
First of all, I think that in order to find father of the father you should use something like this, try it with a large assembly and choose the piece in which your father is phantom, and he will give you back the next father who is not a phantom.

Sub Main()
Dim oAsmCompDef As AssemblyComponentDefinition
oAsmCompDef = ThisApplication.ActiveDocument.ComponentDefinition
Dim oPart As ComponentOccurrence

'Pick part occurrence
oPart = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kAssemblyLeafOccurrenceFilter, "Seleccione Pieza")
	If oPart Is Nothing Then
		Exit Sub
	Else
		Dim partname As String = oPart.Definition.Document.Displayname
		MessageBox.Show("the origin part is" & partname, "Title")
		Dim Parent As Document = oPart.Definition.Document.ReferencingDocuments.Item(1)
	
		Dim oParentnameA As String = Parent.DisplayName
		MessageBox.Show("parent component searched " & oParentnameA, "Title")' parent component searched, should not be phantom
		
		Dim oBOM As BOM
		oBOM = ThisApplication.ActiveDocument.ComponentDefinition.BOM
		Dim oBOMView As BOMView
		oBOMView = oBOM.BOMViews.Item("Unnamed")'Accesing to Model data Column
		Call FindParent(oBOMView.BOMRows, 0, oParentnameA )

		End If
	End Sub
	
	Sub FindParent(Rows As BOMRowsEnumerator, indent As Integer, oParentnameA As String)'
	    Dim oBOMRow As BOMRow
    For Each oBOMRow In Rows
		Dim oDef As ComponentDefinition
		oDef = oBOMRow.ComponentDefinitions(1)
		Dim oParentName As String = oDef.Document.Displayname
		
		If oParentName <> oParentnameA Then
		
		    If Not oBOMRow.ChildRows Is Nothing Then
		        Call FindParent(oBOMRow.ChildRows, indent + 1,oParentnameA)
		    End If
		End If
		If  oParentName = oParentnameA Then

			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" 
					
			If oBOMStructnumber = 51971 Then
				Dim oDocFile As Document
				oDocFile = oDef.Document
				Dim Parent As Document = oDocFile.ReferencingDocuments.Item(1)
				oParentnameA=Parent.DisplayName
				Dim oBOM As BOM
				oBOM = ThisApplication.ActiveDocument.ComponentDefinition.BOM
				Dim oBOMView As BOMView
				oBOMView = oBOM.BOMViews.Item("Unnamed")'Accesing to Model data Column
				Call FindParent(oBOMView.BOMRows, 0, oParentnameA )
			End If
			
			If oBOMStructnumber <> 51971 Then
				
					MessageBox.Show("the parent is " & oParentnameA & "@" & BOM_Structure, "Title")
					
			End If   
	   End If
	
    Next

End Sub 

     The problem is that once found the value, we should cut the loop, maybe with "exit for" and if instead of a "sub" we use a "function" we could add a "return" and return the value to the sub that we need. I have tried without success, maybe you or maybe the teacher  @chandra.shekar.g  tell us how to do it if that is the way to the result, or maybe to throw a simpler way.

Regarding the amount I can see, I have not inquired into it yet, 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

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report