Python Callback Syntax

   10954   7   1
User Avatar
Member
133 posts
Joined: July 2005
Offline
Hey Guys:

I'm wondering if there's a preferred way to call a function in a PythonModule even handler from a parameter callback. Let's say I have a function called “foo” in my PythonModule. Which of the following is more correct? Or, are they different ways to skin the cat?

kwargs.hdaModule().foo(kwargs)

hou.pwd().hdaModule().foo(kwargs)

hou.node('.').hdaModule().foo(kwargs)

hou.phm().foo(kwargs)


Thanks!
Frankie Rodriguez
Francisco Rodriguez
Effects Animator | Walt Disney Animation Studios
User Avatar
Member
1908 posts
Joined: Nov. 2006
Offline
I prefer some variation of the latter:
hou.phm().foo(hou.pwd())
hou.phm().foo(kwargs)
Graham Thompson, Technical Artist @ Rockstar Games
User Avatar
Member
133 posts
Joined: July 2005
Offline
Thanks Graham!

I take it these are all various flavors of the same thing? Just looking for any gotchas.
Francisco Rodriguez
Effects Animator | Walt Disney Animation Studios
User Avatar
Member
401 posts
Joined:
Offline
I really like:

hou.phm().foo( kwargs )

As this passes all the kwargs into the function
this is not a science fair.
User Avatar
Member
133 posts
Joined: July 2005
Offline
rdg
I really like:

hou.phm().foo( kwargs )

As this passes all the kwargs into the function

Interesting… But won't that require the function to take as many arguments as kwargs?
Francisco Rodriguez
Effects Animator | Walt Disney Animation Studios
User Avatar
Member
1908 posts
Joined: Nov. 2006
Offline
Not really. kwargs is just a dictionary so that is the only arg the function takes. Whether or not the function actually uses everything in the dictionary is up to you.

I do like passing kwargs and usually do if the function requires more than just the node argument (parm name, instance number, etc). If it just needs the node though I generally just pass hou.pwd(), leaving me the option of using the function elsewhere as well.
Graham Thompson, Technical Artist @ Rockstar Games
User Avatar
Member
133 posts
Joined: July 2005
Offline
Graham:

Sounds like you'd then need to key off the dictionary inside your func, right? Assuming you did: hou.phm().myfunc(kwargs)

def func1(kwargs):
inst = kwargs
parmVal = kwargs
Francisco Rodriguez
Effects Animator | Walt Disney Animation Studios
User Avatar
Member
1908 posts
Joined: Nov. 2006
Offline
Yep, just like that.
Graham Thompson, Technical Artist @ Rockstar Games
  • Quick Links