05-11-2015
04:00 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
05-11-2015
04:00 PM
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