know every execution command name within the current session

By Xiaodong Liang

The question is to know the list of all commands that have been executed in the session. OnActivateCommand of UserInputEvents will be helpful. In this sample below, UserInputEvents starts and an array records every execution command name. If the commands count exceeds 100, the event stops, print all the commands which have ever executed.

Dim oCommandList As  ArrayList  
Dim oUserEvents As UserInputEvents 
 
Sub startEvent()
 
    _InvApplication = _
    Runtime.InteropServices.Marshal. _
    GetActiveObject("Inventor.Application")
 
    oCommandList = New ArrayList()
    ' assume we have got Inventor application       
    oUserEvents =  _ 
        _InvApplication.CommandManager.UserInputEvents 
 
    AddHandler oUserEvents.OnActivateCommand, _
        AddressOf oUserEvents_OnActivateCommand
End Sub
Sub stopEvent()
    RemoveHandler oUserEvents.OnActivateCommand, _
        AddressOf oUserEvents_OnActivateCommand
End Sub
Sub  oUserEvents_OnActivateCommand( _
                  ByVal CommandName As String, _
                  ByVal Context As Inventor.NameValueMap)
 
    If oCommandList.Count < 100 then
        oCommandList.Add(CommandName)
    Else
        Dim oIndex As Integer 
        For oIndex = 0 to oCommandList.Count 
            Debug.Print (oCommandList(oIndex))
        Next
    End If
 
End Sub

Comments

Leave a Reply

Discover more from Autodesk Developer Blog

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

Continue reading