Hi, new to the Inventor Product and API - I am developing an API to output BOMS to text for import into my ERP system, and I found the following code example, which simply outputs the ItemNumber and PartNumber for each child row, but how do I get the actual Assembly Part Number itself? My goal is to produce one row for each parent / child with BOTH the parent and child part numbers:
ParentID ChildID ItemNumber Qty Per
TOP_LEVEL CHILD-1 1 1
CHILD-1 CHILD-1-1 1.1 2
CHILD-1 CHILD-1-2 1.2 1
TOP-LEVEL CHILD-2 2 1
CHILD-2 CHILD-2-1 2.1 1
CHILD-2 CHILD-2-2 2.2 3
CHILD-2 CHILD-2-3 2.3 1
This script does a great job of blowing through the BOM of the document I have open (an assmebly called 530902), but it simply begins by listing the first component and its Item ID, but I am never output the Assembly ID itself.
Any help is appreciated, Thanks.
Public Sub IterateRows _
(oBOMRows As BOMRowsEnumerator, indent As Integer)
Dim oBOMRow As BOMRow
Dim Cntr
Dim PieceNO
Cntr = 1
For Each oBOMRow In oBOMRows
' Let's only get the first definition
' It would only be more than one if rows were merged
Dim oDef As ComponentDefinition
Set oDef = oBOMRow.ComponentDefinitions(1)
Dim partNumber As String
partNumber = oDef.Document.PropertySets( _
"{32853F0F-3444-11D1-9E93-0060B03C1CA6}")("Part Number").Value
PieceNO = Right("000000" & oBOMRow.ItemNumber, 6)
Debug.Print Tab(indent); PieceNO + " " + partNumber
If Not oBOMRow.ChildRows Is Nothing Then
Call IterateRows(oBOMRow.ChildRows, indent + 1)
End If
Cntr = Cntr + 1
Next
End Sub
Public Sub IterateThroughStructuredBOM()
Dim oAsm As AssemblyDocument
Set oAsm = ThisApplication.ActiveDocument
Dim oBOM As BOM
Set oBOM = oAsm.ComponentDefinition.BOM
' Make sure it's enabled
oBOM.StructuredViewEnabled = True
oBOM.StructuredViewFirstLevelOnly = False
Dim oBOMView As BOMView
Set oBOMView = oBOM.BOMViews("Structured")
Call IterateRows(oBOMView.BOMRows, 1)
End Sub
The output looks like this:
000001 530902-003
000002 530902-004
000003 530902-005
000004 530902-006
000005 530902-007
000006 530902-010
000007 530902-011
000008 530902-012
000009 530902-013
000010 530902-014
000011 530902-015
000012 530902-016
000013 530902-017
000014 530902-018
000015 530902-019
000016 530902-020
000017 530902-021
000018 530902-022
000019 530902-023
000020 530902-024
000021 530902-025
000022 530902-026
000023 530902-027
000024 530902-028
000025 530902-029
000026 530902-030
000027 530902-031
000028 530902-032
000029 530902-033
0029.1 530902-034
0029.2 530902-035
000030 530902-036
000031 530902-037
000032 530902-038
000033 530902-001
Solved! Go to Solution.
Hi @Anonymous
You could just make a few small changes like this:
Public Sub IterateRows(ByVal oBOMRows As BOMRowsEnumerator, _ ByVal parentNumber As String, _ ByVal indent As Integer) Dim oBOMRow As BOMRow For Each oBOMRow In oBOMRows ' Let's only get the first definition ' It would only be more than one if rows were merged Dim oDef As ComponentDefinition Set oDef = oBOMRow.ComponentDefinitions(1) Dim partNumber As String partNumber = oDef.Document.PropertySets( _ "{32853F0F-3444-11D1-9E93-0060B03C1CA6}")("Part Number").Value Dim PieceNO As String PieceNO = Right("000000" & oBOMRow.ItemNumber, 6) Debug.Print Tab(indent); PieceNO & " " & parentNumber & "<=" & partNumber If Not oBOMRow.ChildRows Is Nothing Then Call IterateRows(oBOMRow.ChildRows, partNumber, indent + 1) End If Next End Sub Public Sub IterateThroughStructuredBOM() Dim oAsm As AssemblyDocument Set oAsm = ThisApplication.ActiveDocument Dim oBOM As BOM Set oBOM = oAsm.ComponentDefinition.BOM Dim partNumber As String partNumber = oAsm.ComponentDefinition.Document.PropertySets( _ "{32853F0F-3444-11D1-9E93-0060B03C1CA6}")("Part Number").Value ' Make sure it's enabled oBOM.StructuredViewEnabled = True oBOM.StructuredViewFirstLevelOnly = False Dim oBOMView As BOMView Set oBOMView = oBOM.BOMViews("Structured") Call IterateRows(oBOMView.BOMRows, partNumber, 1) End Sub
The idea is to send the parent component part number as a parameter to the next level in the structure, then you know to which parent these components belong.
Regards,
Jens Bejer Pedersen
Developer, Symetri A/S
Jens, this worked great! Thanks for this. I do have one more question - again, not being a CAD expert, I am VP of Development for an ERP software company, working on an interface to extract the Item and Bom data from CAD files to bring into my database as an Item List and BOM.
Do you know if and where Description and Revision data is stored at each level of this structure - Top Level, Assemblies and Parts, so that can be brought in as well?
Thanks, again, this has been a huge help, and I really appreciate it!
Ken Hayes
Hello @Anonymous
In Inventor these informations are all in the iProperties.
Unfortunately the API has a different grouping of the iProperties than the Inventor user interface, so you have to dig into the API help to find the iProperties you need.
I have extended the code i showed to also get the standard iProperty Description and Revision Number:
Public Sub IterateRows(ByVal oBOMRows As BOMRowsEnumerator, _ ByVal parentNumber As String, _ ByVal indent As Integer) Dim oBOMRow As BOMRow For Each oBOMRow In oBOMRows ' Let's only get the first definition ' It would only be more than one if rows were merged Dim oDef As ComponentDefinition Set oDef = oBOMRow.ComponentDefinitions(1) Dim partNumber As String partNumber = oDef.Document.PropertySets( _ "{32853F0F-3444-11D1-9E93-0060B03C1CA6}")("Part Number").Value Dim descrip As String descrip = oDef.Document.PropertySets( _ "{32853F0F-3444-11D1-9E93-0060B03C1CA6}")("Description").Value Dim revNum As String revNum = oDef.Document.PropertySets( _ "{F29F85E0-4FF9-1068-AB91-08002B27B3D9}")("Revision Number").Value Dim PieceNO As String PieceNO = Right("000000" & oBOMRow.ItemNumber, 6) Debug.Print Tab(indent); PieceNO & " " & parentNumber & "<=" & partNumber & _ ", Version " & revNum & ", " & descrip If Not oBOMRow.ChildRows Is Nothing Then Call IterateRows(oBOMRow.ChildRows, partNumber, indent + 1) End If Next End Sub Public Sub IterateThroughStructuredBOM() Dim oAsm As AssemblyDocument Set oAsm = ThisApplication.ActiveDocument Dim oBOM As BOM Set oBOM = oAsm.ComponentDefinition.BOM Dim partNumber As String partNumber = oAsm.ComponentDefinition.Document.PropertySets( _ "{32853F0F-3444-11D1-9E93-0060B03C1CA6}")("Part Number").Value Dim descrip As String descrip = oAsm.ComponentDefinition.Document.PropertySets( _ "{32853F0F-3444-11D1-9E93-0060B03C1CA6}")("Description").Value Dim revNum As String revNum = oAsm.ComponentDefinition.Document.PropertySets( _ "{F29F85E0-4FF9-1068-AB91-08002B27B3D9}")("Revision Number").Value Debug.Print "TopAssembly " & partNumber & ", Version " & revNum & ", " & descrip ' Make sure it's enabled oBOM.StructuredViewEnabled = True oBOM.StructuredViewFirstLevelOnly = False Dim oBOMView As BOMView Set oBOMView = oBOM.BOMViews("Structured") Call IterateRows(oBOMView.BOMRows, partNumber, 1) End Sub
The lines in red shows how to get these two iProperties.
You also have to consider that many places where they use Inventor they use some custom iProperties for these data values, and not necessarily the standard iProperties, so you have to look at the actual data samples to get the right properties.
Further is that Inventor only stores the current values of these properties, the revision history is often stored in the Vault PDM system.
Regards,
Jens Bejer Pedersen
Developer, Symetri A/S
Can't find what you're looking for? Ask the community or share your knowledge.