A Problem with Attribute Helper and a Fix

A partner notified me about a problem he had found with my Attribute Helper add-in that I wasn’t aware of. He told me that if you have the new “Interactive Tutorial” and “Attribute Helper” add-ins both loaded, then Inventor will crash when you shut it down with the dialog below.

Error message dialog showing 'COM object that has been separated from its underlying RCW cannot be used.' with an 'OK' button.

but had a good idea of the cause. I wasn’t following my own advice from this post almost a year ago. I made the changes recommended there so that my Deactivate method of the add-in went from this:


Public Sub Deactivate() Implements Inventor.ApplicationAddInServer.Deactivate
    ' Release objects.
    Marshal.FinalReleaseComObject(g_inventorApplication)
    g_inventorApplication = Nothing

    If Not m_attributeButtonDef Is Nothing Then
        Marshal.FinalReleaseComObject(m_attributeButtonDef)
    End If

    If Not m_UIEvents Is Nothing Then
        Marshal.FinalReleaseComObject(m_UIEvents)
        m_UIEvents = Nothing
    End If

    System.GC.WaitForPendingFinalizers()
    System.GC.Collect()
End Sub

To this:


Public Sub Deactivate() Implements Inventor.ApplicationAddInServer.Deactivate
    ' Release objects.
    m_attributeButtonDef = Nothing
    m_UIEvents = Nothing
End Sub

With that change, the crash went away. I hadn’t published a new version of the “Attribute Helper” add-in for a couple of years so I’ve made this change and created a new installer. You can get the latest version of Attribute Helper here. After installing make sure that you’re running the latest version by checking that the version is 2.6, as shown below.

AttributeHelperVersion

They are The source code for the add-in is also available on GitHub.

-Brian


Comments

One response to “A Problem with Attribute Helper and a Fix”

  1. Maybe I should post this on a forum…
    If I set an Attribute to a sketchedsymbol (the symbol on the sheet, not the definition!) in a drawingdocument and save this as a template (save a copy in the template folder), when I use the template for new drawings, the attributes are gone… Tested on german Inventor 2016 Pro.
    Is this by design? Is this a bug? Are Attributes generally wiped on creating new files?
    Thanks!
    BR,
    Daniel

Leave a Reply

Discover more from Autodesk Developer Blog

Subscribe now to keep reading and get access to the full archive.

Continue reading