Community
Inventor Programming - iLogic, Macros, AddIns & Apprentice
Inventor iLogic, Macros, AddIns & Apprentice Forum. Share your knowledge, ask questions, and explore popular Inventor topics related to programming, creating add-ins, macros, working with the API or creating iLogic tools.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

BomView Error (any Autodesk employee's got a answer)

5 REPLIES 5
Reply
Message 1 of 6
wowens63
763 Views, 5 Replies

BomView Error (any Autodesk employee's got a answer)

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

 

 

5 REPLIES 5
Message 2 of 6
wowens63
in reply to: wowens63

so no one knows why this crashes?

Message 3 of 6
Vladimir.Ananyev
in reply to: wowens63

Could you please test Document.ReleaseReference method instead of Close method.

From API help:

This method  releases the reference that gets added if a document is opened invisibly through the API. Releasing the reference on a hidden document makes it a candidate for closure the next time Inventor closes all unreferenced documents.

Let us know the result please.


Vladimir Ananyev
Developer Technical Services
Autodesk Developer Network

Message 4 of 6
wowens63
in reply to: Vladimir.Ananyev

That does stop the Error, thank you..but now i'm unable to save the current assembly. please see attached file

 

 

 

Message 5 of 6
Vladimir.Ananyev
in reply to: wowens63

Is SaveAll command suitable in your workflow?  If yes then you may try the following code 

Dim oCommandMgr As CommandManager = oApp.CommandManager 
Dim oControlDef As ControlDefinition = oCommandMgr. _ 
    ControlDefinitions.Item("AppSaveAllCmd") 
'oApp.SilentOperation = True 
Call oControlDef.Execute() 
'oApp.SilentOperation = False

Vladimir Ananyev
Developer Technical Services
Autodesk Developer Network

Message 6 of 6
wowens63
in reply to: Vladimir.Ananyev

thank you for your time spent looking in to this. All i'm really trying to do is access the Master Bill of Material so I decided to go with changing the LOD to Master is Needed. see code below. FYI i'm using Inventor 2012

 

 

Public Sub BomTest(ByVal InventorApp As Inventor.Application, ByVal oAssDoc As AssemblyDocument)

        If InventorApp Is Nothing Then
            Exit Sub
        End If

        If oAssDoc Is Nothing Then
            Exit Sub
        End If

        If InventorApp.ActiveEditDocument.DocumentType = DocumentTypeEnum.kAssemblyDocumentObject Then
            If oAssDoc IsNot InventorApp.ActiveEditDocument Then
                MsgBox("This Program was designed not to work in edit mode", MsgBoxStyle.Exclamation, InventorApp.Caption)
                Exit Sub
            End If
        End If

        Try
            If oAssDoc.Dirty Then
                MsgBox("The assembly must be saved before performing the Bill of Materials" & vbCrLf & "operation.", MsgBoxStyle.Exclamation, InventorApp.Caption)
                Exit Sub
            End If
        Catch ex As Exception
            MsgBox(ex.ToString)
        End Try


        Dim oCurrentLOD As LevelOfDetailRepresentation = Nothing
        Dim oRepMgr As RepresentationsManager = oAssDoc.ComponentDefinition.RepresentationsManager
        oCurrentLOD = oRepMgr.ActiveLevelOfDetailRepresentation

        InventorApp.StatusBarText = "Accessing Master Level Of Detail"

        InventorApp.ScreenUpdating = False

        Try
            If oAssDoc.LevelOfDetailName <> "Master" Then
                Dim oMasterLOD As LevelOfDetailRepresentation = oRepMgr.LevelOfDetailRepresentations.Item("Master")
                oMasterLOD.Activate(True)
            End If
        Catch ex As Exception
            oCurrentLOD = Nothing
        End Try

        If oAssDoc.LevelOfDetailName <> "Master" Then
            MsgBox("The Level Of Detail needs to be set to Master!")
        Else
            Try
                Dim m_oBOM As BOM = oAssDoc.ComponentDefinition.BOM

                m_oBOM.StructuredViewEnabled = True
                m_oBOM.StructuredViewFirstLevelOnly = False
                m_oBOM.StructuredViewDelimiter = "."

                Dim m_oBOMView As BOMView = Nothing

                For Each oview As BOMView In m_oBOM.BOMViews
                    If oview.ViewType = BOMViewTypeEnum.kStructuredBOMViewType Then
                        m_oBOMView = oview
                    End If
                Next

                If m_oBOMView IsNot Nothing Then
                    Dim oBOMRows As Inventor.BOMRowsEnumerator = m_oBOMView.BOMRows

                    If oBOMRows IsNot Nothing Then
                        For Each row As Inventor.BOMRow In oBOMRows
                            Dim sItemNumber As String = row.ItemNumber
                        Next
                    End If
                End If
            Catch ex As Exception
                MsgBox("Unknown Error")
            End Try
        End If

        If oCurrentLOD IsNot Nothing Then
            If oRepMgr.ActiveLevelOfDetailRepresentation IsNot oCurrentLOD Then
                oCurrentLOD.Activate(True)
            End If
        End If

        InventorApp.ScreenUpdating = True

        oAssDoc = Nothing

    End Sub

 

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report