Jump to content
Sign in to follow this  
Christoph_H

How to get viewport handles for created points with addpoint()

Recommended Posts

you are creating static handles, which are only limited to hardcoded amount

for the example of dynamic handles created using python viewport states as mentioned above you can have a look at Rbd Constraints From Rules or PointWeld SOPs

Share this post


Link to post
Share on other sites

Hi,
I have to ask again for help.
I have recently started with python and therefore still have Problems.

This script is placed in the | type proberties | interactive | viewer state |:

1. By adding newer points the effect changes only if I press apply at viewer state
2. Somehow the program did not accept the relative path to the parameter. How does that work?
3.
and I haven't been able to create new handles yet

I would be interested in how a clean structure of such a script would be written

help would be great. 
many thanks.

import hou
import viewerstate.utils as su


picker_folder = str(hou.evalParm('/obj/geo1/picker/folder0')) #Somehow the program did not accept the relative path to the parameter. How does that work?

pickerx = "picker"+picker_folder+"x"
pickery = "picker"+picker_folder+"y"
pickerz = "picker"+picker_folder+"z"

print(pickerx,pickery,pickerz)

#print(picker_folder)

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

        self.translate_handle = hou.Handle(self.scene_viewer, "Translate")

    def onEnter(self, kwargs):
        self.translate_handle.show(True)
        
    def onHandleToState(self, kwargs):
        """ Used with bound dynamic handles to implement the state 
        action when a handle is modified.
        """

        handle = kwargs["handle"]
        parms = kwargs["parms"]
        mod_parms = kwargs["mod_parms"]
        prev_parms = kwargs["prev_parms"]
        ui_event = kwargs["ui_event"]

        self.log(parms)

    def onStateToHandle(self, kwargs):
        """ Used with bound dynamic handles to implement the handle 
        action when a state node parm is modified.
        """

        handle = kwargs["handle"]
        parms = kwargs["parms"]
        node = kwargs["node"]

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

    state_typename = kwargs["type"].definition().sections()["DefaultState"].contents()
    state_label = "picker"
    state_cat = hou.sopNodeTypeCategory()

    template = hou.ViewerStateTemplate(state_typename, state_label, state_cat)
    template.bindFactory(State)
    template.bindIcon(kwargs["type"].icon())

    # bind a static handle to node parameters. 
    template.bindHandleStatic( "translate", "Translate", 
        [
            (pickerx, "tx"),
            (pickery, "ty"),
            (pickerz, "tz")
        ])


    return template

 

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×