Josh,
Thanks for the reply. This looks to be very helpful. It appears to answer
another issue I've been trying to address and that is if a component is set
as a reference or phantom. I believe the second function
(GenerateBillOfMaterialsRange) does this, correct?
So, the trick here is "oDoc As InventorApprentice.ApprenticeServerDocument".
This allows the program instance to be in assembly mode and still get part
data, correct? So, I guess the idea is that using the ApprenticeServer....
one can gain access to all of Inventors objects from "behind the scenes".
I was able to get my program to work but, the user has to use two different
buttons and has to actually open the part instance to push the data into the
SQL table for our ERP system. The BoM routine had to do two things, one
create a part for the BoM itself in the PartMaster SQL table and create a
BoM in the BillOfMaterial table in SQL.
If anybody wants the code, I'll post it on a different thread subject.
Thanks,
Steve
wrote in message news:5529136@discussion.autodesk.com...
does this help? It was written for Excel, but could be modified for Access.
It only gets one property (Part Name), but could be modified to query a
number of properties. Notice that there is only one
ApprenticeServerDocument that is the assembly document.
------------------------------------------------------------------------
' retrieves property from Inventor document, uses name based lookup of
property
Public Function GetInventorProperty(oDoc As
InventorApprentice.ApprenticeServerDocument, sName) As
InventorApprentice.Property
Dim oPropSet As InventorApprentice.PropertySet
Dim oProp As InventorApprentice.Property
On Error Resume Next
For Each oPropSet In oDoc.PropertySets
Set oProp = oPropSet.Item(sName)
If Err Then
Err.Clear
Else
Set GetInventorProperty = oProp
Exit Function
End If
Next oPropSet
On Error GoTo 0
End Function
Public Function GenerateBillOfMaterialsRange(oDoc As
InventorApprentice.ApprenticeServerDocument, oStart As Range) As Range
If oDoc.DocumentType <> kAssemblyDocumentObject Then Exit Function
Dim oAsmDef As Inventor.AssemblyComponentDefinition
Set oAsmDef = oDoc.ComponentDefinition
Dim oBOM As Inventor.BOM
Set oBOM = oAsmDef.BOM
Dim val As Variant
Dim i As Integer
i = 0
Dim oCompDef As ComponentDefinition
Dim oPropSet As PropertySet
Dim oBOMRow As Inventor.BOMRow
For Each oBOMRow In oBOM.BOMViews.Item(1).BOMRows
If oBOMRow.BOMStructure <> kPhantomBOMStructure _
Or oBOMRow.BOMStructure <> kReferenceBOMStructure Then
Set oCompDef = oBOMRow.ComponentDefinitions.Item(1)
val = GetInventorPropertyValue(oCompDef.Document, "Part Number")
' check type of value to write to cell
If IsNumeric(val) Then
oStart.Offset(i, 0).Value = val
Else
oStart.Offset(i, 0).Value = val
End If
oStart.Offset(i, 1).Value = oBOMRow.TotalQuantity
i = i + 1
End If
Next oBOMRow
End Function
Public Sub GenerateAssemblyBOM()
Dim oSheet As Worksheet
Set oSheet = Application.ActiveSheet
Dim fd As FileDialog
Set fd = Application.FileDialog(msoFileDialogFilePicker)
With fd
.AllowMultiSelect = False
.Filters.Add "Assemblies", "*.iam", 1
End With
'Use the Show method to display the File Picker dialog box and return
the user's action.
'The user pressed the action button.
If fd.Show = -1 Then
' create Apprentice server
Dim oIV As New InventorApprentice.ApprenticeServerComponent
Dim oIVDoc As InventorApprentice.ApprenticeServerDocument
Set oIVDoc = oIV.Open(fd.SelectedItems(1))
oSheet.Cells(1, 1) = fd.SelectedItems(1)
GenerateBillOfMaterialsRange oIVDoc, oSheet.Cells(2, 1)
End If
'Set the object variable to Nothing.
Set fd = Nothing
End Sub