Archicad C++ API
About Archicad add-on development using the C++ API.
SOLVED!

Register keyboard command that triggers C++ addon functionality

BenjiDev
Enthusiast

I was reading this quesiton: https://community.Graphisoft.com/t5/Developer-forum/Exactly-what-can-you-do-with-Python/td-p/355343 about rotating elements using keystrokes and I have been looking for a way to do this from a C++ Addon.

 

Triggering functionality using keyboard commands is common practice in software and something users expect. How does this work in a C++ Addon? Simply put I would like to run some functionality when the user hits a specific keyboard combination.

 

I know the user can bind a keyboard shortcut to open addons that appears under say Options->My Addon using Options->Work Environment->Shortcut Schemes->Keyboard Shortcuts. But an addon might have multiple actions that each should be bound to different keyboard shortcuts. It would be very nice for an addon to be able to "register" commands that the user can bind keyboard shortcuts to, but i haven't found a way to do this.

1 ACCEPTED SOLUTION

Accepted Solutions
Solution
poco2013
Mentor

Yes- Generally you assign one or more commands to each script. The scripts are very small and created in seconds. Here's a typical 10 line example:

 

from Archicad import ACConnection
import Archicad
conn = ACConnection.connect()
acc = conn.commands
act = conn.types
acu = conn.utilities
parameters = {}
parameters["command"] = "YourCommand"
parameters["inParams"] = ['param One','param two', 'etc.']
response = acc.ExecuteAddOnCommand(act.AddOnCommandId('AdditionalJSONCommands','Dialog'),parameters)
print(response['outParams2'])

 

On the AddOn side, you just use a if-else to detect which command, call the appropriate function and return the results, if any. The AddOn requires configuration of a class to handle the interface, however, you just include the pre-configured cpp & hpp files and a JSON schema for verification and your done. Generally, I use one AddOn to receive multiple commands. This is what Tibor of Graphisoft has done with his examples.

Gerry

Windows 11 - Visual Studio 2022; ArchiCAD 27

View solution in original post

5 REPLIES 5
BenjiDev
Enthusiast

One solution I can think of is to create one C++ Addon for each action, the user can bind a keyboard shortcut to each addon and run the desired functionality when the addon is "opened". But there surely is a better way.

poco2013
Mentor

The 'trick' that I use is to use a 'StreamDeck' by Elgoto. You can create multiple python scripts of only a few line each (once created-- can be easily duplicated) in which you assign a action to each button. Each small script calls either a C++AddOn or a different function within one AddOn. You do this  through the Python API "CommandHandler" interface which is only a few lines to be copy/paste in all the scripts. Then changing the "commands" is only a one/two line change.And once done in each script-- never need be repeated. This involves some knowledge of the C++ API. The Python script is elementary.

Gerry

Windows 11 - Visual Studio 2022; ArchiCAD 27

Thanks, Ive only used the C++ API so far so I am not familiar with python scripting. But what you said is interesting. 

Could you explain more about "assigning an action to each button" is this done programatically in the python script?

Solution
poco2013
Mentor

Yes- Generally you assign one or more commands to each script. The scripts are very small and created in seconds. Here's a typical 10 line example:

 

from Archicad import ACConnection
import Archicad
conn = ACConnection.connect()
acc = conn.commands
act = conn.types
acu = conn.utilities
parameters = {}
parameters["command"] = "YourCommand"
parameters["inParams"] = ['param One','param two', 'etc.']
response = acc.ExecuteAddOnCommand(act.AddOnCommandId('AdditionalJSONCommands','Dialog'),parameters)
print(response['outParams2'])

 

On the AddOn side, you just use a if-else to detect which command, call the appropriate function and return the results, if any. The AddOn requires configuration of a class to handle the interface, however, you just include the pre-configured cpp & hpp files and a JSON schema for verification and your done. Generally, I use one AddOn to receive multiple commands. This is what Tibor of Graphisoft has done with his examples.

Gerry

Windows 11 - Visual Studio 2022; ArchiCAD 27

Great thanks 😄