If you know PartNumber then you may easily get quantity via iLogic function:
quantity = ThisBOM.CalculateQuantity("Model Data", partNumber)
But if your BOM contains overridden quantities then you need to use Inventor API BOMRow.TotalQuantity property for every BOMRow in the BOMView.
(See details here: http://forums.autodesk.com/t5/Inventor-Customization/Exportar-Static-Quantity-da-BOM-para-o-Excel/m-...)
AssemblyDocument ->ComponentDefinition ->BOM->BOMViews->BOMView->BOMRows->BOMRow->TotalQuantity is giving the quantities of the components in the assembly from BOM table.
The following VBA sample illustrates this technique.
Sub GetQuantities()
' a reference to the assembly document.
' This assumes an assembly document is active.
Dim oAssyDoc As AssemblyDocument
Set oAssyDoc = ThisApplication.ActiveDocument
Dim oAssyDef As AssemblyComponentDefinition
Set oAssyDef = oAssyDoc.ComponentDefinition
' Get the Representations Manager object.
Dim repMgr As RepresentationsManager
Set repMgr = oAssyDef.RepresentationsManager
' activate LOD Master - necessary to get BOM object !!!
Dim oMasterLOD As LevelOfDetailRepresentation
Set oMasterLOD = repMgr.LevelOfDetailRepresentations.Item(1)
oMasterLOD.Activate
'set a reference to the BOM
Dim oBOM As BOM
Set oBOM = oAssyDef.BOM
' Make sure that the "Parts Only" view is enabled.
oBOM.PartsOnlyViewEnabled = True
Call oBOM.SetPartNumberMergeSettings(True)
'set a reference to the "Parts Only" BOMView
Dim oBOMView As BOMView
Set oBOMView = oBOM.BOMViews.Item("Parts Only")
Dim oBOMRow As BOMRow
For Each oBOMRow In oBOMView.BOMRows
'Set a reference to the primary ComponentDefinition of the row
Dim oCompDef As ComponentDefinition
Set oCompDef = oBOMRow.ComponentDefinitions.Item(1)
Dim oPartNumProperty As Property
Dim oDescripProperty As Property
Dim Qty As String
If TypeOf oCompDef Is VirtualComponentDefinition Then
'Get the Virtual Component property that contains the "Part Number"
Set oPartNumProperty = oCompDef.PropertySets _
.Item("Design Tracking Properties").Item("Part Number")
'Get the Virtual Component property that contains the "Description"
Set oDescripProperty = oCompDef.PropertySets _
.Item("Design Tracking Properties").Item("Description")
Qty = oBOMRow.TotalQuantity
Debug.Print oBOMRow.ItemNumber; " "; oPartNumProperty.value; " Qty="; _
Qty; " "; oDescripProperty.value
Else
'Get the file property that contains the "Part Number"
'The file property is obtained from the parent
'document of the associated ComponentDefinition.
Set oPartNumProperty = oCompDef.Document.PropertySets _
.Item("Design Tracking Properties").Item("Part Number")
'Get the file property that contains the "Description"
Set oDescripProperty = oCompDef.Document.PropertySets _
.Item("Design Tracking Properties").Item("Description")
Qty = oBOMRow.TotalQuantity
Debug.Print oBOMRow.ItemNumber; " "; oPartNumProperty.value; " Qty="; _
Qty; " "; oDescripProperty.value
End If
Next
Beep
End Sub
iLogic function iProperties.Value("ComponentName", "Custom", "PropertyName") allows you to save any value in the desired custom iProperty:
iProperties.Value("ComponentName", "Custom", "PartQty") = TotalQuantity
or
iProperties.Value("Custom", "PartQty") = TotalQuantity
Does this help?
Vladimir Ananyev
Developer Technical Services
Autodesk Developer Network