08-10-2023
03:18 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
08-10-2023
03:18 AM
OK. Try this:
Sub Main
Dim oInvApp As Inventor.Application = ThisApplication
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)
Dim oTM As Transaction = oInvApp.TransactionManager.StartTransaction(oAsmDoc, "CheckAndSetProps")
Call RecursiveCheckAndSetProps(oBOMView.BOMRows, oTekNum)
oTM.End()
End Sub
Private Sub RecursiveCheckAndSetProps(ByVal oRowsElements As BOMRowsEnumerator, ByVal oTekNum As String)
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
Dim oListNumb() As String = oBOMRow.ItemNumber.Split(".")
Dim oBOMItemNumber As String = oListNumb(oListNumb.Length-1)
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
Dim sTek As String = ""
Try : sTek = oCustom("TekNum").Value : Catch : End Try
Call RecursiveCheckAndSetProps(oBOMRow.ChildRows, sTek)
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.