Cycling handle alignment in a Python handle

   2039   7   1
User Avatar
Member
406 posts
Joined: April 2017
Offline
I have a custom xform handle implemented as a Viewer State for an HDA. I need to be able to adjust some parameters under the hood if a user presses M to change the handle's alignment... is there a property of the handle that I can query in onHandleToState to know what alignment the handle is currently in?
MOPs (Motion Operators for Houdini): http://www.motionoperators.com [www.motionoperators.com]
User Avatar
Member
151 posts
Joined: June 2019
Online
Is that a completely custom python handle or a builtin xform handle bound to python viewer state?

For custom python handle you can use hou.SceneViewer.runStateCommand to interop with the state. Basically you can run state command in your handles onParmChangeEvent and notify current state about changing the alignment (scene viewer passed to handle on initialization in kwargs["scene_viewer"])

If it's a builtin one I think there's no way unfortunately. I also had the same issues and afaik there is no exposed handle settings other than visibility.

You probably can intercept M (btw for production it's probably safer to use hou.hotkeys.assignments("h.pane.gview.handle.xform.cycle_alignment")) in onKeyEvent and manually set the alignment via hou.Handle.applySettings but I'm not sure if you can do that for builtin handles.
User Avatar
Staff
452 posts
Joined: Feb. 2018
Offline
There is no API on hou.Handle to modify a handle behavior explicitly.

As for the python handle calling python states command, it technically works but from a design standpoint it's best to avoid any explicit coupling between a python handle and the active python state.
Edited by mabelzile - July 14, 2021 09:19:09
User Avatar
Member
406 posts
Joined: April 2017
Offline
elovikov
You probably can intercept M (btw for production it's probably safer to use hou.hotkeys.assignments("h.pane.gview.handle.xform.cycle_alignment")) in onKeyEvent and manually set the alignment via hou.Handle.applySettings but I'm not sure if you can do that for builtin handles.

Thanks! This works well-- it's an entirely custom handle, but intercepting the hotkey works as well as anything. Here's the event code if anyone else is wondering... the "local" parameter on my node determines how the handle is aligned (world or local) in onStateToHandle.

    def onKeyEvent(self, kwargs):
        event = kwargs["ui_event"]
        node = kwargs["node"]
        key = event.device().keyString()
        if key.upper() in [f.upper() for f in hou.hotkeys.assignments("h.pane.gview.handle.xform.cycle_alignment")]:
            # switch between local and world space.
            node.parm("local").set(not node.evalParm("local"))
            return True
MOPs (Motion Operators for Houdini): http://www.motionoperators.com [www.motionoperators.com]
User Avatar
Member
151 posts
Joined: June 2019
Online
Oh, interesting. I was actually suggesting key intercepting for builtin handle. I thought for your custom one you have cycling implemented in the handle itself (like in move_tool_handle in demo handles) and you just want to notify the state.

btw have you tried custom handles on macs? In my experience I just can't make them work because the whole gadgets system seems broken on osx (at least on my end in 18.5 on Big Sur)
User Avatar
Member
151 posts
Joined: June 2019
Online
mabelzile
As for the python handle calling python states command, it technically works but from a design standpoint it's best to avoid any explicit coupling between a python handle and the active python state.

I agree but still, notifying the state about settings changed seems natural. We're even receiving onHandleToState when settings changed but we just have it with the empty mod_parms. So we know that handle state was changed, we just don't know which one.

I'm currently writing handles for my sdf editor and I ended up using parameters for behavior control instead of settings as it seems more flexible (though I don't need an ui and don't actually care about saving handles state to scene)
User Avatar
Member
406 posts
Joined: April 2017
Offline
elovikov
Oh, interesting. I was actually suggesting key intercepting for builtin handle. I thought for your custom one you have cycling implemented in the handle itself (like in move_tool_handle in demo handles) and you just want to notify the state.

btw have you tried custom handles on macs? In my experience I just can't make them work because the whole gadgets system seems broken on osx (at least on my end in 18.5 on Big Sur)

I was caught off guard by the handle cycling, but a user working with my tool was trying to use the M hotkey to cycle handles, and apparently my handle was hearing that signal but interpreting it incorrectly.

I haven't been able to test on OSX, I don't have a Mac here. Hopefully one of my Mac userbase will let me know...
MOPs (Motion Operators for Houdini): http://www.motionoperators.com [www.motionoperators.com]
User Avatar
Staff
452 posts
Joined: Feb. 2018
Offline
elovikov
mabelzile
As for the python handle calling python states command, it technically works but from a design standpoint it's best to avoid any explicit coupling between a python handle and the active python state.

I agree but still, notifying the state about settings changed seems natural. We're even receiving onHandleToState when settings changed but we just have it with the empty mod_parms. So we know that handle state was changed, we just don't know which one.

I'm currently writing handles for my sdf editor and I ended up using parameters for behavior control instead of settings as it seems more flexible (though I don't need an ui and don't actually care about saving handles state to scene)

Can you log a bug for this ? It looks like the mod_parms is not updated.
Edited by mabelzile - July 19, 2021 09:20:56
  • Quick Links