深入瞭解Python在HDA中的應用
阿新 • • 發佈:2020-01-09
Event Handler
在HDA中,要建立Python指令碼,需要先選擇一個事件處理器(EventHandle),他表示你要在什麼時候執行你現在所建立的指令碼命令
On Created (在節點建立時,執行指令碼)
如選擇此項編輯Python指令碼,Python將會在節點建立時執行Python中的命令
Python Model (Python模式)
這一項會使建立的指令碼在使用過程中根據使用者設定執行
可以使用這一項給節點設定引數提示等功能
On Delete(在節點建立時執行指令碼)
Python在Houdini節點上的常用方法
Set Color 設定顏色
node = kwargs['node'] #獲取當前節點 context = hou.pwd() #當前節點的父物件 node.setColor(hou.Color((0.584,0.776,1))) #設定當前節點顏色
Node 建立節點
try: out = context.createNode('null','OUT_render') #從當前節點的父物件建立節點 out.setInput(0,node) #設定out節點輸入端為當前節點node out.setColor(hou.Color(0,0)) #設定out節點的顏色 except: pass
Print and Button feedback 列印字元和按鈕反饋
def CacheGeo(): #在OnCreate建立一些自定的方法,然後可以在節點引數中呼叫 this = hou.pwd() #獲取當前節點 print "\nCaching......!" filecache = hou.node(this.path() + '/cache_geo') #獲取設定當前節點內cache_geo的路徑為filecache filecache.parm('execute').pressButton() #獲取filecache節點上execute的狀態 this.setColor(hou.Color((0.584,1))) #設定節點顏色 def ReloadGeo(): this = hou.pwd() print "\nLoaded successfully" filecache = hou.node(this.path() + '/report_geo') filecache.parm('reload').pressButton() this.setColor(hou.Color((0.475,0.812,0.204))) output = hou.node(this.path() + '/output0') #設定當前節點內output0節點的路徑為output geo = output.geometry() #獲取output的geometry並賦予到geo(要求出geometry才可以求這個節點上的geometry屬性) print len(geo.points()) #列印geo的點數
設定這兩個按鈕(cache_geo、report_geo)執行時呼叫不同的方法,執行不同的操作
引數呼叫PythonScripts
hou.pwd().hdaModule().CacheGeo()
以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支援我們。