Jump to content

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


Christoph_H

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

Link to comment
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

 

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...