Houdini has the ability to automatically execute Python scripts when parameters on a node are updated If you write Python in the Callback Script in the Edit Parameter Interface, that Python will be executed when the value changes.
Since there is only one line of space to write in the Callback Script column, define a function to be executed somewhere and call it.
The easiest way to define it is in the menu Windows> Open the Python Source Editor and write the function definition in it
If you write a function here, you can access it from hou.session
For example
def func():
pass
In the case of the function definition, you can call it with hou.session.func ()
I will actually write The following is an example
#Copy by specifying parameters
def Send(from_path, to_path, params):
from_path = hou.nodes(from_path.split())
to_path = hou.nodes(to_path.split())
params = params.split()
for f, t in zip(from_path,to_path):
for p in params:
t.parm(p).set(f.evalParm(p))
It is a code that receives the copy source path and copy destination path as a character string (string) and copies while looping with for.
To operate Houdini with Python, use the classes and functions included in hou. ↓ will be helpful hou package https://www.sidefx.com/docs/houdini/hom/hou/index.html
What to use when operating a node ↓ hou.node HOM function hou.nodes HOM function hou.Node class
What to use when manipulating parameters ↓ hou.parm HOM function hou.Parm class
For example, if you write ʻa = hou.node ('../ null'), you can use this ʻa
to operate the node of '../ null'
.
Since some class that inherits the hou.Node
type is assigned to ʻa`, hou.Node class is used to use this. houdini / hom / hou / Node.html) is good. There are various in-class functions.
When manipulating parameters, if you write b = a.parm ('tx')
, the class assigned to b
is a class of type hou.Parm, and you can manipulate parameters using b
→ hou.Parm class
Functions often used in the hou.Parm class are probably set
and ʻeval Writing
b.set (888)updates
tx to
888 You can assign a value such as
888 to
cwith
c = b.eval ()`
By the way, using ʻa and
bis redundant, so if you write
hou.node ('../ null'). Parm ('tx'). Set (888)`, it's one shot.
Create null1 and null2 nodes and copy the values
In the null1 Callback Script, write the following to call the function
hou.session.Send('.','../null2','t2x t2y t2z')
'.'
Is a string representing the calling node (null1 in this case)
t2x`` t2y
t2z
is the name of the parameter
When I put 0.3 in t2x of null1, t2x of null2 also changed to 0.3
In the above example, the function was executed immediately by changing t2x
, but you can also create a button and copy the value when the user presses the button.
In this case, write the script you want to execute when the button is pressed in the button Callback Script.
Recommended Posts