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

Hi, i've had the same problem. This is the rule that i used. Hope this helps you...

Sub Main
Dim oAssemblyDocument As AssemblyDocument
oAssemblyDocument = ThisDoc.Document

Dim oAssemblyComponentDefinition As AssemblyComponentDefinition
oAssemblyComponentDefinition = oAssemblyDocument.ComponentDefinition

Dim oBOM As BOM
oBOM = oAssemblyComponentDefinition.BOM
oBom.StructuredViewEnabled = True
Dim oBOMView As BOMView
oBOMView = oBom.BOMViews(2) 'Structured view
oBom.StructuredViewFirstLevelOnly = False
oBom.StructuredViewDelimiter = "."

Call RecursiveCheckAndSetProps(oBOMView.BOMRows)

End Sub

Sub RecursiveCheckAndSetProps(ByVal oRowsElements As BOMRowsEnumerator)

        For Each oBOMRow As BOMRow In oRowsElements
            Dim oComponentDefinition As ComponentDefinition
            oComponentDefinition = oBOMRow.ComponentDefinitions.Item(1)

            Dim oBOMItemNumber As String
            oBOMItemNumber = oBOMRow.ItemNumber() 'this is item number in the BOM
           ' MessageBox.Show(oBOMItemNumber, "BOM Number") 'just to show what's going on
            Dim oComponentDefinitionPropertySet As PropertySet
            oComponentDefinitionPropertySet = oComponentDefinition.Document.PropertySets.Item("Inventor User Defined Properties")
            'custom property tab
 			Try
                'if already exists then set it 
                oComponentDefinitionPropertySet.Item("BOM Number").Value = oBOMItemNumber
            Catch ex As Exception
                'else add it
                oComponentDefinitionPropertySet.Add(oBOMItemNumber, "BOM Number")
            End Try
            'creates the custom property and inputs the value
            If Not oBOMRow.ChildRows Is Nothing Then
				Call RecursiveCheckAndSetProps(oBOMRow.ChildRows)
            End If
        Next
End Sub