- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hi there was similar topic, but i have different issue.
I'm also trying to find a way to catch the Item number (structured BOM) and create an iProperty "BOM Number" in every assembly's parts.
Problem is that, rule doesn't add BOM Number to parts that have the same filename (i have many parts with the same filenames - and i'm not going to change it! they always are in different folder) . It adds only to the first occurance as i understand.
When using this :
For i = 1 To oBOMRow.ComponentDefinitions.Count
iProperties.Value(oBOMRow.ComponentDefinitions(i).Document.DisplayName, "Custom", "BOM Number") = oBOMItemNumber
Next
When using this instead of above code :
oComponentDefinitionPropertySet.Item("BOM Number").Value = oBOMItemNumber
Problem is when i have many parts with the same Partname- it adds BOM Number to the first of it.
Can anyone help me ?
Whole rule here, and also attached with my TEST FILES.
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
'Logger.Info(oBOMItemNumber & " BOM Number") 'just to show what's going on
Dim oComponentDefinitionPropertySet As PropertySet
oComponentDefinitionPropertySet = oComponentDefinition.Document.PropertySets.Item("Inventor User Defined Properties")
'Try
'If already exists Then Set it
On Error Resume Next
For i = 1 To oBOMRow.ComponentDefinitions.Count
iProperties.Value(oBOMRow.ComponentDefinitions(i).Document.DisplayName, "Custom", "BOM Number") = oBOMItemNumber
'oComponentDefinitionPropertySet.Item("BOM Number").Value = oBOMItemNumber
Logger.Info(oBOMRow.ComponentDefinitions(i).Document.DisplayName & " - " & oBOMItemNumber)
Next
'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
Solved! Go to Solution.