A couple of questions on stackoverflow and the Revit API discussion forum prompted me to pick up the age-old issue of keyboard shortcuts again.
Plus, I'd like to point out some news from the AEC Hackathon in New York and the AECbytes newsletter:
I attended the AEC Hackathon in New York last year, and one of the numerous results was the vA3C WebGL three.js-based 3D AEC viewer:
This time around, my colleague Jaime Rosales Duque participated and shared his experiences on the AEC Hackathon New York City 2.0.
For more details on the innovative projects created there, see the AEC Hackathon NYC recap.
For an overview over a couple of exciting AEC happenings that I have not mentioned previously, I find Lachmi Khemlani's semi-annual AECbytes AEC technology newsletter a very worthwhile read, mentioning Trimble ProjectSight, AllTrak Cloud and Rapid Positioning System, Newforma SmartUse, Conworld and Aconex Dynamic Manuals.
A question was raised on the Revit API discussion forum on how to programmatically retrieve keyboard shortcuts:
Question: Please suggest how can I get list of Revit short keys programmatically.
Answer: The user interface provides a command to export your shortcut keys to XML.
This command may possibly be launched programmatically as well using PostCommand.
It might be tricky to drive programmatically, though. Maybe, you can either use the Revit API PostCommand method, the or .NET UI Automation library to drive the following sequence:
If you use PostCommand, you will have to handle all the dialogues that pop up via the Revit API.
Revitalizer suggests: Just read this file:
As you can see, this is a per-user-file, so there may be several of them on your system.
Question: Is this file always generated automatically, or do you have to launch some Revit command to export it?
Does Revit keep it up to date automatically every time you make a change to the keyboard shortcuts?
Answer: Yes, Revit updates this file just if I change the shortcuts in the GUI.
I don't know if there exists such a file if the user didn't change them yet, but I suppose so since there are not only user defined but also predefined shortcuts, e.g. WF for wireframe display mode.
Further testing shows that the XML file is not present before the use user sets up her first keyboard shortcut.
If it is missing and you use the GUI to make a change to the existing shortcuts, e.g. by adding one, it appears.
Since shortcuts are per user, this information needs to be stored, anyway.
If the user never changed her shortcuts, you can assume that she is using default settings.
To generate a default settings file, you can make a change, retrieve the XML file, and use your newly generated file as a template, minus your change.
Since the KeyboardShortcuts.xml file is localised (CommandName and Paths attributes), one will need to create one template per language.
The CommandId and Shortcuts attributes are language independent. In a German XML file, for example, there is a default MD for "modify", "ändern" in German.
If you just want the CommandId-Shortcuts relationship, you need only one file version, since this relation is language independent.
Another question on the Revit API discussion forum on how to assign a keyboard shortcut to an external command:
Question: How to assign keyboard shortcuts for external commands in the Revit 2015?
For example, I have created an external command to display the element location and want to execute this commend using a keyboard shortcut "CP".
Answer: Its simple. Just go to the Revit Menu and click on options at the bottom right of the popup. Then click on User Interface tab and then select the Keyboard Shortcuts in the middle of the dialog on the right side. From there you can find your custom command and assign a shortcut to it. You can also adjust existing shortcuts and make new shortcuts there for most of the commands in Revit.
Response: Thanks for your reply, but I want to do this programmatically.
Answer: Here is an old description on how to achieve that back in 2009.
Things have changed since then, though.
The Revit 2011 API introduced keyboard shortcut support for API buttons:
API buttons found on the Ribbon can be assigned a keyboard shortcut. Buttons created by applications registered using manifest files now use an id based on their application id and button name to provide a unique identifier for the button. The keyboard shortcut will be maintained even if the order of registration of API applications changes.
This functionality was overhauled in the Revit 2013 API:
API commands may now be assigned keyboard shortcuts, and those assignments will be preserved even if add-ins are added, removed or changed in subsequent sessions.
API commands may also be moved to the Quick Access Toolbar, and that assignment will also be preserved even if add-ins are added, removed or changed in subsequent sessions.
Unfortunately, it looks as if the actual assignment still is done manually as described in the Revit help topic on Keyboard Shortcuts.
You will obviously be facing the same issues as described above driving this programmatically.
A query on stackoverflow on how to programmatically create a keyboard shortcut in Revit:
Question: Can I programmatically create a keyboard shortcut for my Revit add-in?
Answer: As explained by the help topics listed above, this can easily be achieved manually.
Programmatically, again, you will have to tackle the issues described above, as far as I know.