08-10-2023
01:08 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
08-10-2023
01:08 AM
I think this is due to the fact that your assembly contains components that cannot be edited, for example: content center components. I added a check (line 23), if it doesn't help then put the code section (lines 31 - 36) in a Try-Catch.
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)
Dim oDoc As Document = oCompDef.Document
If Not oDoc.IsModifiable Then Continue For
'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 = 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
oSamenstelling.Value = oTekNum & " POS" & oBOMNumb.Value
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.