We value your input! Please participate in Archicad 28 Home Screen and Tooltips/Quick Tutorials survey
2022-09-09 05:10 PM - last edited on 2022-09-10 12:13 PM by Laszlo Nagy
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.
Solved! Go to Solution.
2022-09-11 07:30 PM
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.
2022-09-09 05:17 PM
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.
2022-09-09 06:14 PM
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.
2022-09-11 04:32 PM
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?
2022-09-11 07:30 PM
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.
2022-09-12 12:44 AM
Great thanks 😄