Jump to content

python questions about OnInputChanged event handler


pushpathadam

Recommended Posts

Hi,

I'm trying to figure out how to call a function with the OnInputChanged event handler.

I have a function foo() defined in the Python module that I'd like to run anytime I change the

the first input to my asset.

Tried

hou.pwd().hdaModule().foo(kwargs[0])

in the OnInputChanged section of my the scripts tab in my asset without luck.

So a few questions I have are

  • Is this the correct workflow.? function lives in the python module but the gets called from the event handler section?
  • Does the function for a specific event handler need to have the same name as the handler?
  • Finally, what's the correct syntax for passing keynames besides 'node'to kwargs ..or multiple keynames since some
  • of the handlers can use more..

thanks!

Tom

Link to comment
Share on other sites

An event handler script is just a script and isn't run from within the object in the sense that hou.pwd() won't return the instance of the object created. That's what kwargs['node'] is for. In your case you'd want to do this:

asset = kwargs['node']
asset.hdaModule().foo(asset)

You get the instance of your asset from the kwargs dict and then call to its PythonModule and pass in the instance of the node, or you can just pass in kwargs again.

The workflow is correct as long as you use the above mentioned code.

You can't control what is passed to kwargs through event handlers/callbacks. The info in the dictionary is specific info for the event and is just generated by Houdini. You can modify them from inside the handler though in the case you wanted to pass more info to whatever you were calling through simple dictionary manipulation though there's really no point in that you could just provide the same info inside the function.

asset = kwargs['node']
kwargs['something'] = somevalue
asset.hdaModule().foo(kwargs)

Edited by graham
Link to comment
Share on other sites

  • 2 weeks later...

Thank you Graham,

Got it working both ways, passing the multiple kwargs or the kwargs object.

For anyone curious, to pass multiple kwargs the syntax is

In the OnInputChanged section:

kwargs['node'].hdaModule().update(kwargs['node'],kwargs['input_index'])

Inside the python module:

def update(node,index):

currentpath = node.path()

current = hou.node(currentpath)

cam = current.inputs()[int(index)]

To pass the whole kwargs object, (tried it in the OnNameChanged section) the syntax is:

In the OnNameChanged section:

kwargs['node'].hdaModule().updateOldName(kwargs)

Inside the python module:

def updateOldName(test):

old_name = test['old_name']

node = test['node']

currentpath = node.path()

current = hou.node(currentpath)

I was testing this on a mac so in both cases I found the easiest way to check

if the variables were passing properly was using this as a quick and easy "print statement":

hou.ui.displayMessage(currentpath)

-Tom

Edited by pushpathadam
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...