'Extracting BoM and Part custom properties...

'Extracting BoM and Part custom properties...

Anonymous
Not applicable
1,495 Views
4 Replies
Message 1 of 5

'Extracting BoM and Part custom properties...

Anonymous
Not applicable

Hello,

 

I'm developing a VBA program to transfer an
assembly's BoM to an Access database table (called BOM) but, also tranfer the
custom i-properties of the parts (listed in the BoM) into another table called
PartMaster.

 

The BoM extraction part was not to hard (kudos to
all those out there who had posts that accomplished this task) but, getting
access to the custom i-properties of the parts has been the hard part.  I
don't want to have to open each part in the assembly and extract it but,
maybe that is what has to be done to gain access to the meta-data.

 

Any advice would be appreciated.

 

Thanks,

 

Steve Elting

Senior Mechanical Engineer,

Universal Labeling
Systems
0 Likes
1,496 Views
4 Replies
Replies (4)
Message 2 of 5

Anonymous
Not applicable

From the plethora of replies, I see I may need to rephrase my
question.

 

Is is possible to extract part (.ipt)  i-properties
(including custom) while in an assembly (.iam)?

 

If this still is not clear please let me know.

 

Thanks


style="PADDING-RIGHT: 0px; PADDING-LEFT: 5px; MARGIN-LEFT: 5px; BORDER-LEFT: #000000 2px solid; MARGIN-RIGHT: 0px">


Hello,

 

I'm developing a VBA program to transfer an
assembly's BoM to an Access database table (called BOM) but, also tranfer the
custom i-properties of the parts (listed in the BoM) into another table called
PartMaster.

 

The BoM extraction part was not to hard (kudos to
all those out there who had posts that accomplished this task) but, getting
access to the custom i-properties of the parts has been the hard part.  I
don't want to have to open each part in the assembly and extract it but,
maybe that is what has to be done to gain access to the
meta-data.

 

Any advice would be appreciated.

 

Thanks,

 

Steve Elting

Senior Mechanical Engineer,

Universal Labeling
Systems
0 Likes
Message 3 of 5

Anonymous
Not applicable
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
0 Likes
Message 4 of 5

Anonymous
Not applicable
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
0 Likes
Message 5 of 5

shastu
Advisor
Advisor

I tried copying this code into a new module and trying to get it to work but when I run it, I get a "Compile error:  User-defined type not defined".  What am I doing wrong?

0 Likes