Preset option with shortcut or custom layout in CommandData plugin
-
Hello,
I have a CommandData Python plugin that contains different options.
When I assign a shortcut to my CommandData, or add it to a custom layout, it opens with the default options.
Is is possible to define different shortcuts or custom layout icons that pass parameters to my CommandData plugin and then preset different options ?
For example, imagine a shortcut that execute the Optimize command with the Unused Points checked, and an other one unchecked.
Is it possible ?Thanks,
-
Yes you can do this with scripts. I have done this in the past with my Dials plugin.
Let's say you have a CommandData.
You simply create a script which does perform c4d.CallCommand(pluginID, option)
where <pluginID> is the plugin id of the CommandData, and option is the CallCommand::ExecuteSubID to be executed.You then assign a shortcut / icon to your script ... and you're done.
You can create as many scripts / shortcuts as you want, each with a different <option> value -
Hi,
as @C4DS said, the easiest way of doing it would be to create script or CommandData to launch your main commandData.
Using commandData would allow you to hide them from the extension menu and still being able to assign shortcut on them.
You could also assign different shortcut and check which one has called your plugin.
You could find the shortcut list assign to your command and react to them by order. First one will trigger this option, second that, etc.The issue is that you must rely on the shortcut order.
def Execute(self, doc): # retrieve the shortcut list for x in range(c4d.gui.GetShortcutCount()): shortcutBc = c4d.gui.GetShortcut(x) # you have to check the combinaison, that could be a bit hard because shortcut can have up to 4 keys and modifier. if shortcutBc[1000] == PLUGIN_ID: for data in shortcutBc: print (data) # Check for specific key pressed bc = c4d.BaseContainer() # user ord('E') or 69 for the e key. do not use ord('e') if c4d.gui.GetInputState(c4d.BFM_INPUT_KEYBOARD, ord('E'), bc): if bc[c4d.BFM_INPUT_VALUE] == 1: print ("option 1") else: print ("e NOT PRESSED")
Cheers,
Manuel -
Thank you very much !