- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
how do I get date form BOM using Ilogic
Sub main() Dim oDoc As AssemblyDocument oDoc = ThisApplication.ActiveDocument Dim oBOM As BOM oBOM = oDoc.ComponentDefinition.BOM oBOM.PartsOnlyViewEnabled = True Dim oBOMView As BOMView oBOMView = oBOM.BOMViews bRows = oBOMView.BOMRows Dim bRow As BOMRow For Each bRow In bRows 'Enter code here Next End Sub
I am trying to build an code that read data form BOM. I want to read
item , part number, qty, description, G_L (Custom), Raw material, Status (Custom)and add to an Excel .
but can´t get the for each to run .... I was trying to rewrite an VBA code I found on the net .. that I beleive would do almost what I want ..( see sample below)... any I did why it fail ... you are welcome to help with the rest of the code
'Public Sub Main() 'Dim oDoc As AssemblyDocument 'Set oDoc = ThisApplication.ActiveDocument 'Dim oBOM As BOM 'Set oBOM = oDoc.ComponentDefinition.BOM 'oBOM.PartsOnlyViewEnabled = True 'Dim oBOMView As BOMView 'Set oBOMView = oBOM.BOMViews.Item("Parts Only") 'Call ExportToExcel(oBOMView.BOMRows) 'End Sub 'Public Function ExportToExcel(bRows As BOMRowsEnumerator) 'Dim xlApp As Excel.Application 'Set xlApp = GetObject("", "Excel.Application.15") 'Dim xlWorkbook As Workbook 'Set xlWorkbook = xlApp.Workbooks.Open("C:\SolidCAD\Inventor Training Files\iLOGIC\Beam\Beam Assembly - BOM.xls") 'Dim xlWorksheet As WorkSheet 'Set xlWorksheet = xlWorkbook.Worksheets.Item("TEST") 'Dim row As Integer 'row = 5 'xlWorksheet.Range("B4").Value = "ITEM" 'xlWorksheet.Range("C4").Value = "QTY" 'xlWorksheet.Range("D4").Value = "DESC" 'xlWorksheet.Range("E4").Value = "Part Number" 'Dim bRow As BOMRow 'For Each bRow In bRows 'Dim rDoc As Document 'Set rDoc = bRow.ComponentDefinitions.Item(1).Document 'Dim docPropertySet As PropertySet 'Set docPropertySet = rDoc.PropertySets.Item("Design Tracking Properties") 'xlWorksheet.Range("B" & row).Value = bRow.ItemNumber 'xlWorksheet.Range("C" & row).Value = bRow.ItemQuantity 'xlWorksheet.Range("D" & row).Value = docPropertySet.Item("Description").Value 'xlWorksheet.Range("E" & row).Value = docPropertySet.Item("Part Number").Value 'row = row + 1 'Next 'xlWorkbook.Save 'xlWorkbook.Close (False) 'xlApp.Quit 'End Function
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Can you try this code and see if it works in iLogic? Please change your excel file and excel sheet if needed, I had copied the same from the code you provided.
Public Sub Main() Dim oDoc As AssemblyDocument oDoc = ThisApplication.ActiveDocument Dim oBOM As BOM oBOM = oDoc.ComponentDefinition.BOM oBOM.PartsOnlyViewEnabled = True Dim oBOMView As BOMView oBOMView = oBOM.BOMViews.Item("Parts Only") Call ExportToExcel(oBOMView.BOMRows) End Sub Public Function ExportToExcel(bRows As BOMRowsEnumerator) ExcelFile ="C:\SolidCAD\Inventor Training Files\iLOGIC\Beam\Beam Assembly - BOM.xlsx" ExcelSheet = "TEST" Dim row As Integer row = 5 GoExcel.CellValue(ExcelFile,ExcelSheet,"B4") = "Item" GoExcel.CellValue(ExcelFile,ExcelSheet,"C4") = "QTY" GoExcel.CellValue(ExcelFile,ExcelSheet,"D4") = "DESCR" GoExcel.CellValue(ExcelFile,ExcelSheet,"E4") = "Material" Dim bRow As BOMRow For Each bRow In bRows Dim rDoc As Document rDoc = bRow.ComponentDefinitions.Item(1).Document Dim docPropertySet As PropertySet docPropertySet = rDoc.PropertySets.Item("Design Tracking Properties") GoExcel.CellValue(ExcelFile,ExcelSheet,"B" & row) = bRow.ItemNumber GoExcel.CellValue(ExcelFile,ExcelSheet,"C" & row) = bRow.ItemQuantity GoExcel.CellValue(ExcelFile,ExcelSheet,"D" & row) = docPropertySet.Item("Description").Value GoExcel.CellValue(ExcelFile,ExcelSheet,"E" & row) = docPropertySet.Item("Part Number").Value row = row + 1 Next GoExcel.Save GoExcel.Close GoExcel.ClearCache End Function
Hope this will be helpful.
Regards,
Dutt Thakar
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Try this. You can edit the properties that you want to copy and add more in the BOLD part in code.
Class BOMEXport Shared row As Integer = 5 Public Sub Main() Dim oDoc As AssemblyDocument oDoc = ThisApplication.ActiveDocument Dim oBOM As BOM oBOM = oDoc.ComponentDefinition.BOM oBOM.StructuredViewEnabled = True oBOM.StructuredViewFirstLevelOnly = False oBOM.StructuredViewDelimiter = "." oBOM.PartsOnlyViewEnabled = True Dim oBOMView As BOMView oBOMView = oBOM.BOMViews.Item("Structured") Call ExportToExcel(oBOMView.BOMRows) End Sub Public Function ExportToExcel(bRows As BOMRowsEnumerator) ExcelFile ="C:\SolidCAD\Inventor Training Files\iLOGIC\Beam\Beam Assembly - BOM.xlsx" ExcelSheet = "TEST" GoExcel.CellValue(ExcelFile,ExcelSheet,"B4") = "Item" GoExcel.CellValue(ExcelFile,ExcelSheet,"C4") = "QTY" GoExcel.CellValue(ExcelFile,ExcelSheet,"D4") = "DESC" GoExcel.CellValue(ExcelFile,ExcelSheet,"E4") = "Part Number"
GoExcel.CellValue(ExcelFile,ExcelSheet,"F4") = "G_L (Custom)" 'add more line below as per your property requirement Dim bRow As BOMRow For Each bRow In bRows Dim rDoc As Document rDoc = bRow.ComponentDefinitions.Item(1).Document Dim docPropertySet As PropertySet docPropertySet = rDoc.PropertySets.Item("Design Tracking Properties") GoExcel.CellValue(ExcelFile,ExcelSheet,"B" & row) = bRow.ItemNumber GoExcel.CellValue(ExcelFile,ExcelSheet,"C" & row) = bRow.ItemQuantity GoExcel.CellValue(ExcelFile,ExcelSheet,"D" & row) = docPropertySet.Item("Description").Value GoExcel.CellValue(ExcelFile,ExcelSheet,"E" & row) = docPropertySet.Item("Part Number").Value 'add more line below as per your property requirement row = row + 1 If Not bRow.ChildRows Is Nothing Call ExportToExcel(bRow.ChildRows) End If Next GoExcel.Save GoExcel.Close GoExcel.ClearCache End Function End Class
Regards,
Dutt Thakar
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
To get custom properties, you need to change the property set. To get all your custom Properties value, you need to reference them with "User defined Properties" in property set. I have added these extra lines to the above code for getting G_L. Replace the below code in Public Function.
Public Function ExportToExcel(bRows As BOMRowsEnumerator) ExcelFile ="C:\SolidCAD\Inventor Training Files\iLOGIC\Beam\Beam Assembly - BOM.xlsx" ExcelSheet = "TEST" GoExcel.CellValue(ExcelFile,ExcelSheet,"B4") = "Item" GoExcel.CellValue(ExcelFile,ExcelSheet,"C4") = "QTY" GoExcel.CellValue(ExcelFile,ExcelSheet,"D4") = "DESC" GoExcel.CellValue(ExcelFile,ExcelSheet,"E4") = "Part Number" GoExcel.CellValue(ExcelFile,ExcelSheet,"F4") = "G_L" 'add more line below as per your property requirement Dim bRow As BOMRow For Each bRow In bRows Dim rDoc As Document rDoc = bRow.ComponentDefinitions.Item(1).Document Dim docPropertySet As PropertySet docPropertySet = rDoc.PropertySets.Item("Design Tracking Properties") GoExcel.CellValue(ExcelFile,ExcelSheet,"B" & row) = bRow.ItemNumber GoExcel.CellValue(ExcelFile,ExcelSheet,"C" & row) = bRow.ItemQuantity GoExcel.CellValue(ExcelFile,ExcelSheet,"D" & row) = docPropertySet.Item("Description").Value GoExcel.CellValue(ExcelFile,ExcelSheet,"E" & row) = docPropertySet.Item("Part Number").Value 'add more line below as per your property requirement Dim docPropertySet1 As PropertySet docPropertySet1 = rDoc.PropertySets.Item("User Defined Properties")
'You can add below all your custom properties, they must be referenced with docPropertySet1
GoExcel.CellValue(ExcelFile, ExcelSheet, "F" & row) = docPropertySet1.Item("G_L").Value row = row + 1 If Not bRow.ChildRows Is Nothing Call ExportToExcel(bRow.ChildRows) End If Next GoExcel.Save GoExcel.Close GoExcel.ClearCache End Function
Hope this will be helpful
Regards,
Dutt Thakar