Transfer parameter values in Python

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. bandicam 2019-11-16 21-57-31-466.jpg

Method

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 bandicam 2019-11-20 10-51-42-016.jpg bandicam 2019-11-16 22-06-49-389.jpg

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))

bandicam 2019-11-16 22-32-19-427.jpg 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 bhou.Parm class

Functions often used in the hou.Parm class are probably set and ʻeval Writingb.set (888)updatestx to 888 You can assign a value such as888 to cwithc = b.eval ()`

By the way, using ʻa and bis redundant, so if you writehou.node ('../ null'). Parm ('tx'). Set (888)`, it's one shot.

Copy from null1 to null2

Create null1 and null2 nodes and copy the values

In the null1 Callback Script, write the following to call the function bandicam 2019-11-16 22-53-26-969.jpg 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 bandicam 2019-11-16 21-44-42-466.jpg

Execute when the button is pressed

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.

bandicam 2019-11-20 10-59-43-402.jpg

In this case, write the script you want to execute when the button is pressed in the button Callback Script. bandicam 2019-11-20 11-03-15-849.jpg

Recommended Posts

Transfer parameter values in Python
Swapping values in Python
Use parameter store in Python
FX Systre Parameter Optimization in Python
HMM parameter estimation implementation in python
Get parameter values ​​in Django templates
Quadtree in Python --2
Python in optimization
CURL in python
Metaprogramming in Python
Python 3.3 in Anaconda
Geocoding in python
SendKeys in Python
Python: Tips-Swap values
Meta-analysis in Python
Unittest in python
Epoch in Python
Discord in Python
Sudoku in Python
DCI in Python
quicksort in python
nCr in python
Plink in Python
Constant in python
Lifegame in Python.
FizzBuzz in Python
Sqlite in python
StepAIC in Python
N-gram in python
LINE-Bot [0] in Python
Disassemble in Python
Reflection in Python
Constant in python
format in python
Scons in Python3
Puyo Puyo in python
python in virtualenv
PPAP in Python
Quad-tree in Python
Reflection in Python
Chemistry in Python
Hashable in python
DirectLiNGAM in Python
LiNGAM in Python
Flatten in python
flatten in python
Zero padding for dynamic variable values in Python
Sorted list in Python
Clustering text in Python
Daily AtCoder # 2 in Python
Implement Enigma in python
Daily AtCoder # 6 in Python
Daily AtCoder # 18 in Python
Edit fonts in Python
Singleton pattern in Python
File operations in Python
Read DXF in python
Daily AtCoder # 53 in Python
Key input in Python
Use config.ini in Python
Daily AtCoder # 33 in Python