Message 1 of 5
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Dear Expert,
I am using VB.Net to fill part's information to excel template. But something is wrong with my code.
BOM in inventor:
Relacing all components in sub-assembly 6
Private Sub btnExportExcel_Click(sender As Object, e As EventArgs) Handles btnExportExcel.Click
invApp = Marshal.GetActiveObject("Inventor.Application")
assemblyDoc = invApp.ActiveDocument
Dim oTemplate As String = "C:\Users\ngocs\OneDrive\Documents\05-Personal Work\01_Test_Files\ExcelTemplates.xls"
Dim oBOM As BOM = assemblyDoc.ComponentDefinition.BOM
oBOM.StructuredViewFirstLevelOnly = False
oBOM.StructuredViewEnabled = True
Dim oBOMView As BOMView
oBOMView = oBOM.BOMViews.Item("Structured")
Dim oPartNumber As Inventor.Property = Nothing
oPartNumber = assemblyDoc.PropertySets("Design Tracking Properties").Item("Part Number")
Dim oPartNumProperty As String
oPartNumProperty = oPartNumber.Value
Dim xlApp As Object = CreateObject("Excel.Application")
Dim xlwb As Object = xlApp.Workbooks.Open(oTemplate)
Dim xlws As Object = xlwb.Worksheets(1)
xlApp.Visible = True
xlws.name = "Structured " & oPartNumProperty
Dim oStartRow As Integer = 1
Call QueryBOMRowProperties(oBOMView.BOMRows, xlApp, xlwb, xlws, oStartRow)
End Sub
Private Sub QueryBOMRowProperties(oBOMRows As BOMRowsEnumerator, ByVal xlApp As Object, ByVal xlwb As Object, ByVal xlws As Object, oStartRow As Integer)
For i = 1 To oBOMRows.Count
Dim oRow As BOMRow
oRow = oBOMRows.Item(i)
Dim oCompDef As ComponentDefinition
oCompDef = oRow.ComponentDefinitions.Item(1)
Dim oPartNumProperty As Inventor.Property
If TypeOf oCompDef Is VirtualComponentDefinition Then
oPartNumProperty = oCompDef.Document.PropertySets.Item("Design Tracking Properties").Item("Part Number")
xlws.Cells(oStartRow, 1) = oRow.ItemNumber
xlws.Cells(oStartRow, 2) = oPartNumProperty.Value
xlws.Cells(oStartRow, 3) = oRow.ItemQuantity
oStartRow = oStartRow + 1
Else
oPartNumProperty = oCompDef.Document.PropertySets.Item("Design Tracking Properties").Item("Part Number")
xlws.Cells(oStartRow, 1) = oRow.ItemNumber
xlws.Cells(oStartRow, 2) = oPartNumProperty.Value
xlws.Cells(oStartRow, 3) = oRow.ItemQuantity
oStartRow = oStartRow + 1
If Not oRow.ChildRows Is Nothing Then
Call QueryBOMRowProperties(oRow.ChildRows, xlApp, xlwb, xlws, oStartRow)
End If
End If
Next
End Sub
Please help me.
Many thanks.
Ngoc Son
Ngoc Son
Autodesk User
Autodesk User
Solved! Go to Solution.