Message 1 of 6
BomView Error (any Autodesk employee's got a answer)

Not applicable
03-04-2013
08:46 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
First off I have a Assembly File Open and LOD set to "Mod" and I want to see the BomView for
Structured and I know you can only see the Structured Bom in LOD set to master. so I open another instance of the document (invisibly) in the Master representation and run code then I close the Document that I just opened invisible.
every thing works fine, then I do the same thing all over again and sometimes it works some times it throws an error and some times Inventor dies..so what is going on this this...see code below... and just FYI if I dont close the invisible Document then I can run the code over and over and over with no error..but I dont want to keep the invisible document open after i'm done with it..
Public Sub BomTest(ByVal InventorApp As Inventor.Application, ByVal oAssDoc As AssemblyDocument) Dim oAssemlyDocument As AssemblyDocument = Nothing Dim oAsmDocMasterLOD As AssemblyDocument = Nothing If InventorApp.ActiveEditDocument.DocumentType = DocumentTypeEnum.kAssemblyDocumentObject Then oAssemlyDocument = InventorApp.ActiveEditDocument Else oAssemlyDocument = oAssDoc End If Try If oAssemlyDocument.Dirty Then MsgBox("You Need to save the Assembly File First!") oAssemlyDocument = Nothing Exit Sub End If Catch ex As Exception MsgBox(ex.ToString) End Try Dim bClose As Boolean = False If oAssemlyDocument.LevelOfDetailName = "Master" Then oAsmDocMasterLOD = oAssemlyDocument Else Try oAsmDocMasterLOD = InventorApp.Documents.Open(oAssemlyDocument.File.FullFileName, False) bClose = True Catch ex As Exception bClose = False MsgBox(ex.ToString) End Try End If If oAsmDocMasterLOD IsNot Nothing Then Dim m_oBOM As BOM = oAsmDocMasterLOD.ComponentDefinition.BOM m_oBOM.StructuredViewEnabled = True m_oBOM.StructuredViewFirstLevelOnly = False m_oBOM.StructuredViewDelimiter = "." Dim m_oBOMView As BOMView = Nothing Try For Each oview As BOMView In m_oBOM.BOMViews If oview.ViewType = BOMViewTypeEnum.kStructuredBOMViewType Then Try m_oBOMView = oview Catch ex As Exception MsgBox("1. Error hit here") m_oBOMView = Nothing End Try Exit For End If Next Catch ex As Exception MsgBox("2. Error hit here") End Try If m_oBOMView IsNot Nothing Then Dim oBOMRows As Inventor.BOMRowsEnumerator = Nothing Try oBOMRows = m_oBOMView.BOMRows Catch ex As Exception MsgBox("3. Error hit here") oBOMRows = Nothing End Try If oBOMRows IsNot Nothing Then For Each row As Inventor.BOMRow In oBOMRows Try Dim sItemNumber As String = row.ItemNumber Catch ex As Exception MsgBox("4. Error hit here") Exit For End Try Next End If End If If bClose = True Then oAsmDocMasterLOD.Close(True) End If End If oAsmDocMasterLOD = Nothing oAssemlyDocument = Nothing End Sub