Python Custom States - SceneViewer.selectGeometry() crashes

   2425   3   2
User Avatar
Member
3 posts
Joined: April 2017
Offline
I'm experimenting with the new python custom states. I tried to implement the “Select Geometry” method (http://www.sidefx.com/docs/houdini/hom/hou/SceneViewer.html#selectGeometry) in the OnEnter() part of my custom state. When I enter my HDA's custom state, it asks for the correct geometry selection, and then crashes when the geometry selection is complete.

I'm curious as to whether I am approaching this in the correct manner. I would like to have a sequence of selections (much like what is done in Tool Scripts). Here's my code, and I have attached the HIP file as well.


from __future__ import print_function

import stateutils
import parmutils
import hou
import traceback


class DrawPoints(object):    
    def __init__(self, state_name, scene_viewer):
        self.state_name = state_name
        self.scene_viewer = scene_viewer

        self._node = None
        self._pressed = False
        self._index = 0
        
    def onEnter(self, kwargs):
        try:
            selection = self.scene_viewer.selectGeometry(
                prompt="Select curve",
                sel_index=0,
                allow_drag=False,
                quick_select=False,
                use_existing_selection=False,
                initial_selection=None,
                initial_selection_type=None,
                ordered=False,
                geometry_types=[hou.geometryType.Primitives,],
                primitive_types=[hou.primType.Polygon,],
                allow_obj_sel=False,
                allow_other_sops=False,
                consume_selections=True
            )
        except Exception as error:
            print(traceback.print_exc())


template = hou.ViewerStateTemplate(
    "selectGeometryCrashes.pystate",
    "Draw Points",
    hou.sopNodeTypeCategory()
)

template.bindFactory(DrawPoints)

Attachments:
selectGeometryCrashes.hipnc (65.2 KB)

User Avatar
Staff
452 posts
Joined: Feb. 2018
Offline
Htinney
I'm experimenting with the new python custom states. I tried to implement the “Select Geometry” method (http://www.sidefx.com/docs/houdini/hom/hou/SceneViewer.html#selectGeometry) in the OnEnter() part of my custom state. When I enter my HDA's custom state, it asks for the correct geometry selection, and then crashes when the geometry selection is complete.

I'm curious as to whether I am approaching this in the correct manner. I would like to have a sequence of selections (much like what is done in Tool Scripts). Here's my code, and I have attached the HIP file as well.


from __future__ import print_function

import stateutils
import parmutils
import hou
import traceback


class DrawPoints(object):    
    def __init__(self, state_name, scene_viewer):
        self.state_name = state_name
        self.scene_viewer = scene_viewer

        self._node = None
        self._pressed = False
        self._index = 0
        
    def onEnter(self, kwargs):
        try:
            selection = self.scene_viewer.selectGeometry(
                prompt="Select curve",
                sel_index=0,
                allow_drag=False,
                quick_select=False,
                use_existing_selection=False,
                initial_selection=None,
                initial_selection_type=None,
                ordered=False,
                geometry_types=[hou.geometryType.Primitives,],
                primitive_types=[hou.primType.Polygon,],
                allow_obj_sel=False,
                allow_other_sops=False,
                consume_selections=True
            )
        except Exception as error:
            print(traceback.print_exc())


template = hou.ViewerStateTemplate(
    "selectGeometryCrashes.pystate",
    "Draw Points",
    hou.sopNodeTypeCategory()
)

template.bindFactory(DrawPoints)

Don't use the HOM geometry selector API, you have to bind the selector with hou.ViewerStateTemplate.bindGeometrySelector instead. See attached sample.

Image Not Found
Edited by mabelzile - Nov. 12, 2018 15:24:34

Attachments:
sop_selection_test.hip (1.2 MB)

User Avatar
Member
3 posts
Joined: April 2017
Offline
Thanks for the suggestion, and the HIP file! Seeing the code certainly helps When I run the HIP file on my instance of Houdini, I have trouble with the operator when it runs OnInstall:

Traceback (most recent call last):
  File "opdef:/Sop/test_selecting?OnInstall", line 5, in <module>
  File "/opt/hfs17.0.352/houdini/python2.7libs/stateutils.py", line 600, in wrapper
    return func(*args,**kwargs)
  File "opdef:/Sop/test_selecting?PythonModule", line 59, in createViewerStateTemplate
  File "/opt/hfs17.0.352/houdini/python2.7libs/stateutils.py", line 782, in debug
    trace = hotkey(state_typename, 'trace', '6', 'Trace callbacks', 'Enable trace for callbacks', state_cat)
  File "/opt/hfs17.0.352/houdini/python2.7libs/stateutils.py", line 751, in hotkey
    hotkey_context = context(state_cat)
  File "/opt/hfs17.0.352/houdini/python2.7libs/stateutils.py", line 749, in context
    raise hou.TypeError('Unsupported hotkey type: %r' % (state_cat))
TypeError: Invalid type.
Unsupported hotkey type: <hou.NodeTypeCategory for Sop>

Based on the error message, it seems like there something I need to do to support the hotkey?
User Avatar
Staff
452 posts
Joined: Feb. 2018
Offline
You need 17.0.375 to load the example scene.

-mab
  • Quick Links