08-09-2023
11:19 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
08-09-2023
11:19 PM
Hi @S.vanderBrug . Not sure I understood you, but I did optimize your current code. Please show on the screenshots what exactly you want to do, I will be happy to help you.
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 = oCustom("BOM Number").Value
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 oCustom As PropertySet = oCompDef.Document.PropertySets.Item("Inventor User Defined Properties")
Dim oBOMNumb, oSamenstelling As Inventor.Property
Try : oBOMNumb = oCustom("BOM Number") : oBOMNumb.Value = oBOMItemNumber
Catch : 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, oTekNum, 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.