Ondrej

Ondrej

About Me

Connect

LOCATION
Not Specified
WEBSITE

Houdini Skills

Availability

Not Specified

My Badges

SideFX Staff
Since Jul 2005

Recent Forum Posts

onKeyEvent issue (python) Sept. 19, 2024, 10:21 a.m.

The new hotkey system in 20.5 does indeed give state hotkey contexts priority during hotkey resolution. However, to take advantage of that, you need to use the hotkey system, i.e., register a hotkey context symbol, hotkey action symbols, and default key bindings for that hotkey context. Without that you're at the mercy of the hard-coded order in which various key event handlers are triggered by Houdini. It also good practice to do in general so that key bindings can be customized through the hotkey manager.

I think the examples/documentation are still a little behind in this respect, so the easiest way to see an example is to look at one of the python states we're shipping. For example, $HFS/houdini/viewer_states/sidefx_clip.py. The way it's done there is designed to work under both the old and new hotkey systems in 20.0 and up, though of course the new system is only used by 20.5 and up.

What you're looking for is the use of the `hou.PluginHotkeyDefinitions` object to register the various hotkey symbols and default bindings with the viewer state template in `createViewerStateTemplate()`.

In the `onKeyEvent()` function, you'll want to note how `viewerstate.utils.hotkeySymbolOrKeyString()` is used instead of the raw key string from the `ui_event`, and compared against a hotkey symbol using `hou.hotkeys.isKeyMatch()`.

The hotkey system is broken in Houdini 20.5 July 29, 2024, 4:18 p.m.

Ondrej
Unfortunately, I don't think there is a way to invoke this type of action script directly through python, or, if there is, I'm aware of it.

Turns out that I was indeed unaware of it. We added a hou.Parm.pressScriptActionButton() method in 20.5.

The hotkey system is broken in Houdini 20.5 July 29, 2024, 10:09 a.m.

kodra
Can one just get the python code of the parameter's script_action Python code as string then eval() it? I know eval() is usually a bad idea for general programming, but if it's just used internally for Houdini...

Anyway it would be more ideal if Houdini's Restart Selecting just be smarter to handle this. It even occupies a quite valuable hotkey
(`) by default. Please make it do better.

Actually, yes, that's technically possible and didn't occur to me. The script is stored in the parameter's spare data (tags, in the HOM vernacular). So, given, the `hou.Parm` or `hou.ParmTuple`, one could get the tags using `parm.parmTemplate().tags()`. It'll be listed as 'script_action'.