首页 > 技术文章 > 小笔记--Python in Houdini

arleyx 2020-10-05 16:33 原文

1,otl中,执行python node中的脚本。callback。

1 def btnClick (passedData):
2     n =  hou.node("/obj/pythonscript1")
3     if n:
4         p = n.parm("btn_example")
5         print dir(p)
6         print p.name()
7         print p.description() # This is the button caption.

 

  Here is the callback code. Remember to switch from Hscript to Python.

exec(hou.node("/obj/pythonscript1").parm('python').eval());btnClick("") 

 2,当运行到某个节点时候更改特定参数,python节点使用

 1 #change parameter
 2 
 3 node = hou.pwd()
 4 geo = node.geometry()
 5 
 6 inputdnode = node.parm("node").eval()
 7 inputvalue = node.parm("value").eval()
 8 
 9 hou.node(inputdnode).setParms({"seed": inputvalue})
10 
11 print hou.node(inputdnode).parm("seed").eval()

 3,列出节点的所有子节点,并且在另一个geo中创建object merge提取

 1 import hou
 2 sourcelevel = hou.node('/obj/subnet1/merged_assets/scn')
 3 allnodes = sourcelevel.children()
 4 
 5 keyworks = "lochabang_station_tunnel_in_asb"
 6 index = 0
 7 for child in allnodes :
 8     if child.type().name()=="attribcreate::2.0" :
 9 
10         childname = child.name()
11         if childname.find(keyworks) != -1 :
12 
13             mergenode = hou.node("/obj/scene_fg").createNode("object_merge")
14             mergenode.setParms({"objpath1": child.path()})
15 
16             #rename
17             mergenodeName = childname.rsplit(".", 1)[-1]
18             mergenode.setName(mergenodeName)
19 
20             print index
21             index += 1
View Code

 

4,make loop中switch节点判断脚本 

1 node = hou.node("../input_data")
2 
3 geo = node.geometry()
4 first_prim = geo.prims()[0]
5 
6 return type(first_prim) in [hou.Volume, hou.VDB]

 5,print path and size in pdg

  

1 import os
2 i = 0
3 files = []
4 for upstream in upstream_items:
5     path = upstream.attrib("__pdg_outputfiles").value()
6     file_size = os.stat(r"{0}".format(path)).st_size 
7     print file_size
8     print path                
View Code

 6, houdini orient to eular

hou.Quaternion( hgeopoint.attribValue( "orient" ) ).extractEulerRotates()

推荐阅读