How to set the shortcut key to a customized command in Inventor?

Issue

"What is the best method to assign a shortcut key to a command in inventor programmatically via the api? I can see on the command definition there are default shortcut key and override shortcut key properties but which one should I set?"

Solution

The following VBA sample demonstrates how to assign a shortcut key to a customized button added to assembly Panel Bar.

Please note the following several points:

If the shortcut key has been consumed by another command, you can’t use it again for your own command, otherwise you will get a runtime error. For example Ctrl+A is used by the “Select All” command, so you can’t use “Ctrl+A” again. You can get a list of all commands and the shortcut keys consumed by Inventor through the “Copy to clipboard” command which is on the keyboard page of the Customize dialog (Tools>Customize¡­).

The DefaultShortcut property can be used to set the command alias, but can’t be used for setting the accelerator, you should use OverrideShortcut instead. The user interface won’t delete the controls you added, so you need to remove them manually from the user interface.

If the shortcut key is used by you, you can’t use it again even if you delete the corresponding control from UI, unless you reset all keys from the keyboard page on the customize dialog.

Shortcuts of kAcceleratorShortcut type are created by defining the OverrideShortcut to an allowed non-alphanumeric character, for example “Alt+U”, but those are defined as key combinations by Inventor, like “Ctrl+C” or “Alt+H”, you can’t use.

 

 

Private WithEvents oBtnDef As ButtonDefinition

Sub AddBtnDefWithShortcut()

Dim oControlDefs As ControlDefinitions

Set oControlDefs = ThisApplication.CommandManager.ControlDefinitions

'Create our own button command

Set oBtnDef = oControlDefs.AddButtonDefinition("MyControldefinition1", "Internal name for my controldef 1", kShapeEditCmdType)

'Assign shortcut key to the button command

oBtnDef.OverrideShortcut = "Alt+A"

' Find the main assembly command bar.

Dim oAsmCmdBar As CommandBar

Set oAsmCmdBar = ThisApplication.UserInterfaceManager.CommandBars.Item("AMxAssemblyPanelCmdBar")

' Add a control to the command bar.

Call oAsmCmdBar.Controls.AddButton(oBtnDef)

End Sub

 

You can delete the button command created by above code, like this:

 

Sub DeleteControlDef()

Dim oControlDefs As ControlDefinitions

Set oControlDefs = ThisApplication.CommandManager.ControlDefinitions

Dim oDef As ControlDefinition

Set oDef = oControlDefs.Item("Internal name for my controldef 1")

oDef.Delete

End Sub


Comments

4 responses to “How to set the shortcut key to a customized command in Inventor?”

  1. Kurt Cardinaels Avatar
    Kurt Cardinaels

    I need to assign “Page Up” and “Page Down”,
    can you help me with this, when i assign “Page Up” i need to type page up and cannot use the shortcut key.
    Thx

  2. ACEDeSmedt Avatar
    ACEDeSmedt

    Try PG.PREC and PG.SUIV

  3. But can you delete default hotkeys so you can bind your own stuff here?

  4. Hi All,
    I want to set a short cut key for Open drawing from part or assembly so I don’t have to choose which is done using Cntrl + O. I want to assign short cut key so only that drawing opens. I Went to customise and keyboard tab and went to open drawing under Control +O. How do I add or edit custom key for just open drawing ? right click or left click on selection doesn’t do anything ?
    Thanks for help.

Leave a Reply

Discover more from Autodesk Developer Blog

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

Continue reading