Message 1 of 7
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hi everyone,
I'm trying to export the BOM to an Excel file with this rule,
AddReference "Microsoft.Office.Interop.Excel.dll"
Imports Microsoft.Office.Interop
Imports Microsoft.Office.Interop.Excel
Sub Main()
'Clear DebugView
Logger.Info("iLogic: DBVIEWCLEAR")
'Declaretions
Dim oAssyDoc As AssemblyDocument
oAssyDoc = ThisApplication.ActiveDocument
Dim oAssyCompDef As AssemblyComponentDefinition
oAssyCompDef = oAssyDoc.ComponentDefinition
'Get path of current document
Dim oPath As String = ThisDoc.Path
'Get BOM from Assembly
Dim oBOM As BOM
oBOM = oAssyCompDef.BOM
Logger.Info("oBOM is set.")
Dim oBOMView As BOMView
oBOMView = oBOM.BOMViews.Item("Strutturata")
'oBOMView = oBOMViews.Item("Parts Only")
oBOMView.Sort("Part Number", 1)
oBOMView.Renumber(1, 1)
Logger.Trace("oBOMView is set.")
oBOM.StructuredViewEnabled = True
'oBOM.PartsOnlyViewEnabled = True
oBOM.StructuredViewFirstLevelOnly = False
Logger.Info("iLogic: BOM_Export Set oBOMView")
'BOM Export
'Copy Job Information Spreadsheet from workspace
sJobBOMTempName = "C:\Users\marco.bonacina\Desktop\Distinta.xlsm"
Dim sJobBOMName As String = String.Concat(oPath,"\","ilogic.xlsm")
Logger.Trace("sJobBOMName: " & sJobBOMName)
Try
IO.File.Copy(sJobBOMTempName, sJobBOMName, True)
Catch ex As Exception
MessageBox.Show(ex.Message)
Return
End Try
Dim sMySheet As String = "NotaOfficina"
Static iCurrRow As Integer = 22
GoExcel.DisplayAlerts = False
GoExcel.Open(sJobBOMName, sMySheet)
'Write BOM values to Excel
Call QueryBOMRowProperties(oBOMView.BOMRows, sJobBOMName, iCurrRow)
oAssyDoc.Save
'Save Excel
GoExcel.Save
GoExcel.Close
'Message box
Dim oMessage As String = "BOM Info"
Dim oCaption As String = "Esportazione completata..."
Dim oButtons As MessageBoxButtons = MessageBoxButtons.OK
Dim oIcons As MessageBoxIcon = MessageBoxIcon.Information
Dim oResult As DialogResult
'Display the MessageBox
oResult = MessageBox.Show(oMessage, oCaption, oButtons, oIcons)
ThisDoc.Launch(sJobBOMName)
End Sub
Public Sub QueryBOMRowProperties(oBOMRows As BOMRowsEnumerator, JobSpreadSheetName As String, iCurrRow As Integer)
'Iterate through the contents of BOM Rows.
Static CurrentRow As Integer = iCurrRow
Dim i As Long
Dim sWriteCell As String
For i = 1 To oBOMRows.Count
'Get the current row
Dim oRow As BOMRow
oRow = oBOMRows.Item(i)
'Set a reference to the primary ComponentDefinition of the row
Dim oCompDef As ComponentDefinition
oCompDef = oRow.ComponentDefinitions.Item(1)
Dim oPropSets As PropertySets
oPropSets = oCompDef.Document.PropertySets
oDesignTrackingPropertySet = oPropSets.Item("Design Tracking Properties")
oInventorSummaryPropertySet = oPropSets.Item("Inventor Summary Information")
oCustomPropertySet = oPropSets.Item("Inventor User Defined Properties")
'Get the file properties that are required
oItemNumberProperty = oRow.ItemNumber
oPartNumProperty = oDesignTrackingPropertySet.Item("Part Number")
oDescripProperty = oDesignTrackingPropertySet.Item("Description")
oTitleProperty = oInventorSummaryPropertySet.Item("Title")
oMaterialProperty = oDesignTrackingPropertySet.Item("Material")
'Trace.WriteLine("iLogic: oItemNumberProperty: " & oItemNumberProperty & " | " & oPartNumProperty.Value & " | " & oDescripProperty.Value & " | " & oTitleProperty.Value)
Logger.Info("iLogic: oItemNumberProperty: " & oItemNumberProperty & " | " & oPartNumProperty.Value & " | " & oDescripProperty.Value & " | " & oTitleProperty.Value)
sWriteCell = "E" & CurrentRow
GoExcel.CellValue(sWriteCell) = oItemNumberProperty
sWriteCell = "L" & CurrentRow
GoExcel.CellValue(sWriteCell) = oRow.ItemQuantity
sWriteCell = "F" & CurrentRow
GoExcel.CellValue(sWriteCell) = oPartNumProperty.Value
sWriteCell = "G" & CurrentRow
GoExcel.CellValue(sWriteCell) = oDescripProperty.Value
sWriteCell = "J" & CurrentRow
GoExcel.CellValue(sWriteCell) = oMaterialProperty.Value
'Recursively iterate child rows if present
If Not oRow.ChildRows Is Nothing Then
GoExcel.Application.Range("A" & CurrentRow, "H" & CurrentRow).Interior.Color = RGB(211, 211, 211)
GoExcel.Application.Range("A" & CurrentRow, "H" & CurrentRow).Borders(XlBordersIndex.xlEdgeTop).Weight = XlBorderWeight.xlThin
GoExcel.Application.Range("A" & CurrentRow, "H" & CurrentRow).Borders(XlBordersIndex.xlEdgeBottom).Weight = XlBorderWeight.xlThin
CurrentRow = CurrentRow + 1
If CurrentRow > 10 Then
GoExcel.Application.Range("A" & CurrentRow, "H" & CurrentRow - 2).Borders(XlBordersIndex.xlEdgeTop).Weight = XlBorderWeight.xlThin
End If
Call QueryBOMRowProperties(oRow.ChildRows, JobSpreadSheetName, CurrentRow)
Else
End If
'Increment current row
CurrentRow = CurrentRow + 1
Next i
GoExcel.Application.Range("A" & CurrentRow-1, "H" & CurrentRow-1).Borders(XlBordersIndex.xlEdgeTop).Weight = XlBorderWeight.xlThin
End Sub
but I can't reorder the list,
or rather within Inventor the list is sorted while in the Excel file it doesn't maintain the correct ordering,
how can I correct it?
I attach images to better understand the problem.


Solved! Go to Solution.