Message 1 of 8
Bill of Materials export to Template by material
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hello all.
I've run into a bit of an issue trying to get my Bill of Materials to export to different sheets depending on material. I've attached my attempt at this. We use a custom property for "Material" and I'm looking to have it export to the template I have based on the custom material property. I got it to export with the designated parameters, but have been unsuccessful in separating by material.
One more thing, This line: oGaugeProperty = oCustomPropertySet.Item("GAUGE")
Errors out, but still successfully brings the custom property "GAUGE" to the document. I like that it still brings the information, but don't like the error. Any help greatly appreciated!
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") xlApp = CreateObject("Excel.Application") xlApp.Visible = True xlWorkbook = xlApp.Workbooks.Open("C:\Temp\Test.xlsx") xlWorksheet = xlWorkbook.Worksheets.Item("Components") Dim row As Integer row = 9 bRows = oBOMView.BOMRows For Each bRow In bRows Dim oMatType As String oMatType = iProperties.Value("Custom", "Material") If oMatType = "GLASTIC" Or "STEEL" Or "GALV." Or "304 STAINLESS" Or "LEXAN" Or "ALUMINUM" xlWorksheet = xlWorkbook.Worksheets.Item("Sheet Metal") Else If oMatType = "CU" xlWorksheet = xlWorkbook.Worksheets.Item("Copper Bar") End If Dim rDoc As Document rDoc = bRow.ComponentDefinitions.Item(1).Document Dim docPropertySet As PropertySet docPropertySet = rDoc.PropertySets.Item("Design Tracking Properties") Dim oPropSets As PropertySets oPropSets = rDoc.PropertySets oInventorSummaryPropertySet = oPropSets.Item("Inventor Summary Information") oRevNumberProperty = oInventorSummaryPropertySet.Item("Revision Number") oCustomPropertySet = oPropSets.Item("Inventor User defined Properties") oGaugeProperty = oCustomPropertySet.Item("GAUGE") xlWorksheet.Range("B" & row).Value = oRevNumberProperty.Value xlWorksheet.Range("C" & row).Value = docPropertySet.Item("Part Number").Value xlWorksheet.Range("D" & row).Value = docPropertySet.Item("Description").Value xlWorksheet.Range("H" & row).Value = bRow.ItemQuantity xlWorksheet.Range("E" & row).Value = oGaugeProperty.Value row = row + 1 Next oNow = DateString & "_" & TimeString oNow = oNow.Replace("/","_") oNow = oNow.Replace(":","_") xlWorkbook.SaveAs(Filename:="C:\Temp\SampleNew_" & oNow & ".xlsx") xlWorkbook.Close (False) xlApp.Quit