H17 python state example not working ?

   1900   5   1
User Avatar
Member
23 posts
Joined: Sept. 2015
Offline
Hi Folks,

I've been trying to create a custom pystate following the documentation:

https://www.sidefx.com/docs/houdini/hom/python_states.html#embed [www.sidefx.com]

But when I instanciate the sop asset I get this error:

Factory not specified of invalid.

Did I miss something ?

Thanks !
Guillaume

Attachments:
test_states.hda (4.4 KB)
states_error.png (27.4 KB)

http://cgtoolbox.com/ [cgtoolbox.com] Houdini tools and scripts for free ! :)
User Avatar
Member
45 posts
Joined: Feb. 2014
Offline
Yeah it appears to be incomplete, you just need to add “template.bindFactory(lambda **kwargs: YourStateClass(**kwargs))”.
User Avatar
Staff
396 posts
Joined: Feb. 2018
Offline
Thomas Bishop
Yeah it appears to be incomplete, you just need to add “template.bindFactory(lambda **kwargs: YourStateClass(**kwargs))”.

Right, the snippet in the doc is missing a call to
bindFactory

Here's a few more examples:

https://www.sidefx.com/forum/topic/56432/?page=4#post-260931 [www.sidefx.com]
https://www.sidefx.com/forum/topic/56432/?page=4#post-260731 [www.sidefx.com]

-mab
Edited by mabelzile - Oct. 12, 2018 09:19:10
User Avatar
Member
323 posts
Joined: Jan. 2015
Online
hi mabz
i think you are linking to the beta forum.

Olaf

mabz
https://www.sidefx.com/forum/topic/56432/?page=4#post-260931 [www.sidefx.com]
https://www.sidefx.com/forum/topic/56432/?page=4#post-260731 [www.sidefx.com]
User Avatar
Member
23 posts
Joined: Sept. 2015
Offline
Great it works with the call to template.bindFactory thanks guys ! Can't wait to play with these new features
http://cgtoolbox.com/ [cgtoolbox.com] Houdini tools and scripts for free ! :)
User Avatar
Staff
396 posts
Joined: Feb. 2018
Offline
Ah, sorry. Thanks for the headsup.

Here are the examples:

1) Add this code to the Python Source Editor:
from __future__ import print_function

import hou

# A minimal state handler implementation. You can 
class MyState(object):
    def __init__(self, state_name, scene_viewer):
        self.state_name = state_name
        self.scene_viewer = scene_viewer

    # Handler methods go here
    def onMouseEvent(self, kwargs):
        dev = kwargs["ui_event"].device()
        print("Mouse:", dev.mouseX(), dev.mouseY(), dev.isLeftButton())

# Choose a name and label 
state_name = "my_test_state"
state_label = "My New Test State"
category = hou.sopNodeTypeCategory()
template = hou.ViewerStateTemplate(state_name, state_label, category)
template.bindFactory(MyState)

# Register the template
def register():
    hou.ui.registerViewerState(template)

2) Hit the Apply button
3) Create a geometry and dive in the network editor
4) Open the Python shell window and type the following:
hou.session.register()
sv = hou.ui.paneTabOfType(hou.paneTabType.SceneViewer)
sv.setCurrentState('my_test_state')
5) You should have something like this printing in the shell when moving the mouse in the viewport
Mouse: 861.0 1412.0 False
Mouse: 859.0 1409.0 False
etc...

The python states used in the scenes below can be found in $HH/viewer_states. The scenes below have notes on how to use the demo.

Image Not Found

Image Not Found

Image Not Found

Image Not Found
Edited by mabelzile - Oct. 12, 2018 11:48:57

Attachments:
pystroke_pig.hip (243.7 KB)
pybend_rubbertoy.hip (250.3 KB)
pydrawcurve.hda (26.9 KB)
pybend.hda (18.9 KB)

  • Quick Links