Fixing Attribute Helper for Inventor 2024




What is attribute helper

Attribute helper is a tool that comes with Inventor that allows you to visualize, create, and edit attributes on a document.

How to install attribute helper

  • Close Inventor
  • Install user tools located at: C:\Users\Public\Documents\Autodesk\Inventor <Current year>\SDK\usertools.msi
  • Open Inventor and a document, head to the tools tab and you should find Attribute Helper

What broke

Issues with COM Object Handling:

After releasing a COM object, it is common practice to set the variable to nothing to prevent any other part of the program from accessing an invalid object. For an unknown reason, setting the variable to nothing throws an exception. This issue specifically affects the buttons added to the context menu.

Problems with Command Names:

When a new window is opened or closed, Attribute Helper checks if it should close itself to avoid issues from having multiple windows open. This function checks if the name of the command matches Attribute Helper’s windows to prevent self-closure. Unfortunately, the command names appear to have changed, causing the function to try to close itself upon opening.

Form Closure Issues:

If the user closes the form using the X in the corner, the clean-up operation does not run, causing the context menu to get stuck on Attribute Helper’s options. This is because the clean-up method is only called by the methods within the program, not the form itself.

How to fix

The fix for these issues is quite simple. Once usertools.msi has been installed, you can find the source code for Attribute Helper at: C:\Users\Public\Documents\Autodesk\Inventor 2024\SDK\UserTools\AttributeHelper

Open the project in your preferred IDE, such as Visual Studio.

If you see any errors related to stdole, you may need to add a reference to OLE Automation.

In AttributeHelperDialog.vb make the following changes:

Modifying the Clean-Up Method:

In CleanUp, you need to comment out two lines and add an event handler.

VB
Private Sub CleanUp(sender As Object, e As FormClosingEventArgs) Handles MyBase.FormClosing
    If Not m_HighlightSet Is Nothing Then
        m_HighlightSet.Clear()
        System.Runtime.InteropServices.Marshal.ReleaseComObject(m_HighlightSet)
        m_HighlightSet = Nothing
    End If

    If Not m_DocEvents Is Nothing Then
        System.Runtime.InteropServices.Marshal.ReleaseComObject(m_DocEvents)
        m_DocEvents = Nothing
    End If

    If Not m_InputEvents Is Nothing Then
        System.Runtime.InteropServices.Marshal.ReleaseComObject(m_InputEvents)
        m_InputEvents = Nothing
    End If

    If Not m_AddAttributeSetButtonDef Is Nothing Then
        System.Runtime.InteropServices.Marshal.ReleaseComObject(m_AddAttributeSetButtonDef)
        'm_AddAttributeSetButtonDef = Nothing
    End If

    If Not m_FindAttributeInDialogButtonDef Is Nothing Then
        System.Runtime.InteropServices.Marshal.ReleaseComObject(m_FindAttributeInDialogButtonDef)
        'm_FindAttributeInDialogButtonDef = Nothing
    End If

    Me.InventorDocument = Nothing

    System.GC.WaitForPendingFinalizers()
    System.GC.Collect()

    m_Entities = Nothing
    m_ObjectList = Nothing
End Sub

Setting these values to nothing after releasing the COM object is good practice but not strictly necessary. As CleanUp is only called on closing the form, there is no risk of the variable being called once released, so removing the problematic lines is sufficient.

Now you should see all references to CleanUp highlighted in red, these can be deleted. The references should be in OK_Button_Click, Cancel_Button_Click, and m_InputEvents_OnActivateOrTerminateCommand.

This modification ensures that CleanUp is now run when the form is closed. These three methods still call CleanUp through Me.Close(), and now the X button on the form will also call the clean-up method.

Updating Command Names:

Add the new names to the If statement in m_InputEvents_OnActivateOrTerminateCommand:

VB
    Private Sub m_InputEvents_OnActivateOrTerminateCommand(CommandName As String, Context As Inventor.NameValueMap) Handles m_InputEvents.OnActivateCommand, m_InputEvents.OnTerminateCommand
        ' Another command was started or one was terminated, so terminate this program.  
        ' The reason this is being used instead of InteractionEvents is because I want 
        ' to use the more general NW arrow selection which has a wider filter range
        ' and is controlled by the user using the selection options.  One issue is
        ' that I don't get notified if the Escape key is pressed while in the NW arrow
        ' command so I can't terminate based on that.
        If Not (CommandName.Contains("ViewCmd") Or CommandName.Contains("WindowCmd") Or CommandName.Contains("AttributeHelper") Or CommandName.Contains("AddAttributeSet")) Then
            m_HighlightSet.Clear()


            ' Check to see if changes have been made.
            If m_Entities.HasChanges Then
                ' See if they want the changes saved.
                If MsgBox("You are aborting the Attribute Helper command and have made changes to attribute data.  Do you want to save the changes?", MsgBoxStyle.YesNo + MsgBoxStyle.Question, "Save Attribute Changes") = MsgBoxResult.Yes Then
                    For Each entity As MyEntity In m_Entities
                        UpdateEntity(entity)
                    Next
                End If
            End If

            'CleanUp()
            Me.Close()
        End If
    End Sub

With these changes made, build the project and copy the DLL over to Inventor. If you have not changed the build location, you should find AttributeHelper.dll in the bin folder of the project. Simply copy this to C:\ProgramData\Autodesk\ApplicationPlugins\AttributeHelper and replace the existing DLL.


Posted

in

by

Tags:

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *