Your browser does not seem to support JavaScript. As a result, your viewing experience will be diminished, and you have been placed in read-only mode.
Please download a browser that supports JavaScript, or enable it if it's disabled (i.e. NoScript).
Hello ! I see the "hotkey" plugin in cinema 4d like "Move Parent", and the shortcut is "7", and i need to press and hold down the shortcut key to execute the plugin. (You can see the Type is Hotkey) So how do i register the "hotkey" plugin in python? Actually i find some hotkey stuf like Command plugin flag in SDK; But i am not sure it's what i want, if it's what i want, how do i use it ? and how do i bind the shortcut key for the plugin ? Thanks
I try to register a CommandDataPlugin with PLUGINFLAG_COMMAND_HOTKE flags, and i assign a shortcut key like this ; . But when i press the shortcut key anything doesn't happen.
CommandDataPlugin
PLUGINFLAG_COMMAND_HOTKE
;
I don't know is i did something is wrong? How can i do it's work correctly?
And the examle code like this:
class Hotket(plugins.CommandData): def Execute(self, doc): print("Hotkey pressed") return True if __name__ == '__main__': plugins.RegisterCommandPlugin(1208170,"Hotkey Test",c4d.PLUGINFLAG_COMMAND_HOTKEY,None,"",Hotket())
Hello !~~ I'm waiting...
Hello @gheyret,
thank you for reaching out to us and please excuse the slight delay. You are misunderstanding the purpose of PLUGINFLAG_COMMAND_HOTKEY, which admittedly is badly explained, and I also had to do some digging myself to understand how this is meant to be used. In bullet points:
PLUGINFLAG_COMMAND_HOTKEY
CommandData
PLUGINFLAG_SMALLNODE
PLUGINFLAG_COMMAND_STICKY
EditorWindow.IsHotkeyDown
GeUserArea.IsHotkeyDown
c4d.gui.GetInputState
c4d.gui.GetShortcut
The description for PLUGINFLAG_COMMAND_STICKY was either always wrong or is outdated, as it does indicate that 'PLUGINFLAG_COMMAND_HOTKEY | PLUGINFLAG_COMMAND_STICKY' will cause CommandData.Execute() to be called - which is not true.
I hope this helps, Ferdinand
"""Example for retrieving the shortcuts for a plugin id. """ import c4d def GetPluginShortcuts(pid: int) -> list[list[tuple[int]]]: """Retrieves the shortcuts for a plugin-id. Args: pid (int): The plugin id. Returns: list[list[tuple[int]]]: The shortcut sequences for the plugin. """ # Get all shortcut containers for the plugin id. count = c4d.gui.GetShortcutCount() matches = [c4d.gui.GetShortcut(i) for i in range(count) if c4d.gui.GetShortcut(i)[c4d.SHORTCUT_PLUGINID] == pid] # build the shortcut data. result = [] for item in matches: sequence = [] for i in range(0, c4d.SHORTCUT_PLUGINID, 10): a, b = item[i], item[i+1] if isinstance(a, (int, float)): sequence.append((a, b)) if sequence != []: result.append(sequence) return result if __name__ == "__main__": # The shortcuts for your plugin id. for item in GetPluginShortcuts(1208170): for a, b in item: print (a, b, c4d.gui.Shortcut2String(a, b)) # The shortcuts for the dissolve tool (multiple shortcuts) for item in GetPluginShortcuts(440000043): for a, b in item: print (a, b, c4d.gui.Shortcut2String(a, b))
Hi @ferdinand , Thank you very much for your detailed reply. I think it is very helpful to me. Cheers!