Python Viewer States Issues

   2571   13   3
User Avatar
Member
538 posts
Joined: Dec. 2006
Offline
I decided to post python viewer states problems in this thread.

In H17.5, after activation with onResume method, the state continues to generate the mouse move event (hou.uiEventReason.Located). But in H18 this type of event stops happening.

Test build: Houdini 18.0.318 Linux version
Edited by Alexey Vanzhula - Dec. 15, 2019 08:16:45
https://gumroad.com/alexeyvanzhula [gumroad.com]
User Avatar
Member
538 posts
Joined: Dec. 2006
Offline
I have solve the problem myself

def onGenerate(self, kwargs):
    kwargs['state_flags']['mouse_drag'] = True

Anyway, according to the documentation:
Mouse drag events are generated by default (True)

this value have to be True by default, but in fact it is not.
Edited by Alexey Vanzhula - Dec. 15, 2019 08:30:56
https://gumroad.com/alexeyvanzhula [gumroad.com]
User Avatar
Member
538 posts
Joined: Dec. 2006
Offline
Another problem. The stroke_demo.hip example works much slower then in H17.5.
https://gumroad.com/alexeyvanzhula [gumroad.com]
User Avatar
Member
538 posts
Joined: Dec. 2006
Offline
In H17.5 and H18 I can't change the wireframe display mode color with the hou.SimpleDrawable.setWireframeColor method.
https://gumroad.com/alexeyvanzhula [gumroad.com]
User Avatar
Member
538 posts
Joined: Dec. 2006
Offline
Currently, we can't draw the drawable geometry immediately after activating the state in the onEnter or onGenerate methods. In the current Python states implementation, we must first move the mouse to update the drawables. So, we need a method to force update.
Edited by Alexey Vanzhula - Dec. 22, 2019 09:18:36
https://gumroad.com/alexeyvanzhula [gumroad.com]
User Avatar
Member
538 posts
Joined: Dec. 2006
Offline
Python states part of the Houdini documentation has a lot of mistakes.
https://gumroad.com/alexeyvanzhula [gumroad.com]
User Avatar
Staff
396 posts
Joined: Feb. 2018
Offline
vux
I decided to post python viewer states problems in this thread.

In H17.5, after activation with onResume method, the state continues to generate the mouse move event (hou.uiEventReason.Located). But in H18 this type of event stops happening.

Test build: Houdini 18.0.318 Linux version

Ok thanks for reporting. It's best to log bugs though so python states issues don't fall in the cracks.
User Avatar
Staff
396 posts
Joined: Feb. 2018
Offline
vux
In H17.5 and H18 I can't change the wireframe display mode color with the hou.SimpleDrawable.setWireframeColor method.
This problem has already been reported and it is not yet fixed.
User Avatar
Staff
396 posts
Joined: Feb. 2018
Offline
vux
Currently, we can't draw the drawable geometry immediately after activating the state in the onEnter or onGenerate methods. In the current Python states implementation, we must first move the mouse to update the drawables. So, we need a method to force update.

Use `hou.GeometryViewport.draw()` to force a redraw.
User Avatar
Member
538 posts
Joined: Dec. 2006
Offline
Thank you for answers!

mabelzile
vux
Currently, we can't draw the drawable geometry immediately after activating the state in the onEnter or onGenerate methods. In the current Python states implementation, we must first move the mouse to update the drawables. So, we need a method to force update.

Use `hou.GeometryViewport.draw()` to force a redraw.

Yes, but this did not work in my case. I will show my example in a few hours
https://gumroad.com/alexeyvanzhula [gumroad.com]
User Avatar
Member
538 posts
Joined: Dec. 2006
Offline
In this example, I want the circle to appear immediately after the state is activated. But it appears only after I start to manipulate the viewport using the Alt key.

class TestTemplate(object):
    _drawable_geo = hou.Geometry()
    circle = hou.sopNodeTypeCategory().nodeVerb("circle")
    circle.setParms({ "type": 2 })
    circle.execute(_drawable_geo, [])
    del circle

    def __init__(self, scene_viewer, state_name):
        self.scene_viewer = scene_viewer
        self.state_name = state_name

        self._drawable = hou.SimpleDrawable(self.scene_viewer, self._drawable_geo, "test_drawable")

    def onGenerate(self, kwargs):
        self._drawable.enable(True)
        self._drawable.show(True)
        
        self.scene_viewer.curViewport().draw()


# UNREGISTER
if hou.ui.isRegisteredViewerState('test_state'):
    hou.ui.unregisterViewerState('test_state')        

# CREATE AND REGISTER
template = hou.ViewerStateTemplate('test_state', 'Test State', hou.sopNodeTypeCategory())
template.bindFactory(TestTemplate)
hou.ui.registerViewerState(template)

# ACTIVATE
scene_viewer = hou.ui.paneTabOfType(hou.paneTabType.SceneViewer)
scene_viewer.setCurrentState("test_state")
https://gumroad.com/alexeyvanzhula [gumroad.com]
User Avatar
Staff
396 posts
Joined: Feb. 2018
Offline
It works fine in H18 with this python state file version:
import hou
import viewerstate.utils as su

class State(object):
    _drawable_geo = hou.Geometry()
    circle = hou.sopNodeTypeCategory().nodeVerb("circle")
    circle.setParms({ "type": 2 })
    circle.execute(_drawable_geo, [])
    del circle

    def __init__(self, scene_viewer, state_name):
        self.scene_viewer = scene_viewer
        self.state_name = state_name

        self._drawable = hou.SimpleDrawable(self.scene_viewer, self._drawable_geo, "test_drawable")

    def onGenerate(self, kwargs):
        self._drawable.enable(True)
        self._drawable.show(True)
        
        #self.scene_viewer.curViewport().draw()

def createViewerStateTemplate():
    """ Mandatory entry point to create and return the viewer state 
        template to register. """

    state_typename = "z"
    state_label = "Z"
    state_cat = hou.sopNodeTypeCategory()

    template = hou.ViewerStateTemplate(state_typename, state_label, state_cat)
    template.bindFactory(State)
    template.bindIcon("MISC_python")


    return template

Tools:
import stateutils as su

viewer = su.findSceneViewer()
viewer.setCurrentState("z")
Edited by mabelzile - Jan. 5, 2020 13:53:40
User Avatar
Member
538 posts
Joined: Dec. 2006
Offline
mabelzile
It works fine in H18 with this python state file version:
import hou
import viewerstate.utils as su

class State(object):
    _drawable_geo = hou.Geometry()
    circle = hou.sopNodeTypeCategory().nodeVerb("circle")
    circle.setParms({ "type": 2 })
    circle.execute(_drawable_geo, [])
    del circle

    def __init__(self, scene_viewer, state_name):
        self.scene_viewer = scene_viewer
        self.state_name = state_name

        self._drawable = hou.SimpleDrawable(self.scene_viewer, self._drawable_geo, "test_drawable")

    def onGenerate(self, kwargs):
        self._drawable.enable(True)
        self._drawable.show(True)
        
        #self.scene_viewer.curViewport().draw()

def createViewerStateTemplate():
    """ Mandatory entry point to create and return the viewer state 
        template to register. """

    state_typename = "z"
    state_label = "Z"
    state_cat = hou.sopNodeTypeCategory()

    template = hou.ViewerStateTemplate(state_typename, state_label, state_cat)
    template.bindFactory(State)
    template.bindIcon("MISC_python")


    return template

Tools:
import stateutils as su

viewer = su.findSceneViewer()
viewer.setCurrentState("z")


Houdini 18.0.340 Linux. The drawable appear only after moving the mouse. Test it from the Python Source Editor.
https://gumroad.com/alexeyvanzhula [gumroad.com]
User Avatar
Member
538 posts
Joined: Dec. 2006
Offline
But it works fine when I use executeDeferred, but with a very small delay:
viewer = su.findSceneViewer()
viewer.setCurrentState("z")
hdefereval.executeDeferred(viewer.curViewport().draw)
Edited by Alexey Vanzhula - Jan. 5, 2020 14:19:43
https://gumroad.com/alexeyvanzhula [gumroad.com]
  • Quick Links