Hi nandakumar.hegde,
Here is an updated example that sets the BOM structure of the occurence and the actual file not to be Reference before exporting the BOM.
I see that you have posted to several other existing threads asking the same question. You might want to remove those posts, or reply to them and point future readers to this example (assuming that it provides a solution.)
I hope this helps.
Best of luck to you in all of your Inventor pursuits,
Curtis
http://inventortrenches.blogspot.com
' a reference to the assembly document.
' This assumes an assembly document is active.
Dim oDoc As AssemblyDocument
oDoc = ThisApplication.ActiveDocument
oCompDef = oDoc.ComponentDefinition
Dim oCompOcc As ComponentOccurrence
'Find all occurrences
For Each oCompOcc In oCompDef.Occurrences
'if component BOM structure is reference then change it to default
If oCompOcc.BOMStructure = BOMStructureEnum.kReferenceBOMStructure Then
'set the occurence not to be Reference
oCompOcc.BOMStructure = BOMStructureEnum.kDefaultBOMStructure
'set the file not to be Reference
oCompOcc.Definition.BOMStructure = BOMStructureEnum.kNormalBOMStructure
End If
Next
'set a reference to the BOM
Dim oBOM As BOM
oBOM = oDoc.ComponentDefinition.BOM
'set the structured view to 'all levels'
oBOM.StructuredViewFirstLevelOnly = False
' Make sure that the structured view is enabled.
oBOM.StructuredViewEnabled = True
'set a reference to the "Structured" BOMView
Dim oStructuredBOMView As BOMView
oStructuredBOMView = oBOM.BOMViews.Item("Structured")
' Export the BOM view to an Excel file
oStructuredBOMView.Export ("C:\temp\BOM-StructuredAllLevels.xls", kMicrosoftExcelFormat)
'define Excel Application object
excelApp = CreateObject("Excel.Application")
'set Excel to run visibly
'change to false if you want to run it invisibly
excelApp.Visible = True
'open the workbook
wb = excelApp.Workbooks.Open("C:\temp\BOM-StructuredAllLevels.xls")
'set all of the columns to autofit
excelApp.Columns.AutoFit
'suppress prompts (such as the compatibility checker)
excelApp.DisplayAlerts = false
'save the workbook
wb.Save
''close the workbook, uncomment if you want to close the xls file at the end
''wb.Close
