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

I write the code intuitively without conducting tests, so there are children's mistakes in it, I hope everything will work well now.

Sub Main
	Dim oAsmDoc As AssemblyDocument = ThisDoc.Document	
	Dim oAsmDef As AssemblyComponentDefinition = oAsmDoc.ComponentDefinition
	Dim oCustom As PropertySet = oAsmDoc.PropertySets.Item("Inventor User Defined Properties")
	Dim oTekNum As String
	Try : oTekNum = oCustom("TekNum").Value
	Catch : oTekNum = "" : End Try
	
	Dim oBOM As BOM = oAsmDef.BOM	
	oBOM.StructuredViewEnabled = True
	oBOM.StructuredViewFirstLevelOnly = False
	Dim oBOMView As BOMView = oBOM.BOMViews(2) 'Structured view
	
	Call RecursiveCheckAndSetProps(oBOMView.BOMRows, oTekNum, 0)
End Sub

Private Sub RecursiveCheckAndSetProps(ByVal oRowsElements As BOMRowsEnumerator,
										ByVal oTekNum As String,
										ByRef indent As Integer)
	For Each oBOMRow As BOMRow In oRowsElements
		Dim oCompDef As ComponentDefinition = oBOMRow.ComponentDefinitions.Item(1)
		
		'by multiplying by two, the itemnumber dodges the periods in the expanded part number.
		Dim oBOMItemNumber As String = oBOMRow.ItemNumber(indent*2) 
		
		Dim oDoc As Document = oCompDef.Document
	    Dim oCustom As PropertySet = oDoc.PropertySets.Item("Inventor User Defined Properties")
		Dim oBOMNumb, oSamenstelling As Inventor.Property
		
		Try : oBOMNumb = oCustom("BOM Number") : oBOMNumb.Value = oBOMItemNumber
	    Catch : oBOMNumb = oCustom.Add(oBOMItemNumber, "BOM Number") : End Try
		
		Try : oSamenstelling = oCustom("Samenstelling")
		Catch : oSamenstelling = oCustom.Add("", "Samenstelling") : End Try
		If oSamenstelling.Value = "" Then
			oSamenstelling.Value = oTekNum & " POS" & oBOMNumb.Value
		End If
		
		If Not oBOMRow.ChildRows Is Nothing Then
			Call RecursiveCheckAndSetProps(oBOMRow.ChildRows, oCustom("TekNum").Value, indent+1)
		End If
	Next
End Sub

 

Andrii Humeniuk - CAD Coordinator, Autodesk Certified Instructor

LinkedIn | My free Inventor Addin | My Repositories

Did you find this reply helpful ? If so please use the Accept as Solution/Like.

EESignature