1.獲取節點某幀的參數值
n = hou.node('/obj/sphere_py01/sphere1')
nTy = n.parm('ty')
nTy.evalAtFrame(4)
測試:似乎得不到由表達式產生的值。
nTy.tuple()得到的是tx,ty,tz的元組
2.刪除某個參數的關鍵幀
nRy = hou.parmTuple('/obj/sphere_py01/r')[1]
nRy.deleteAllKeyframes()
# nRy.deleteKeyframeAtFrame(3)
3.設置某個參數的值
nRy = hou.parmTuple('/obj/sphere_py01/r')[1]
nRy.set(34)
nRy.setExpression("2*frame()")
#獲得表達式字符串
nRy.expression()
#獲得所有的關鍵幀
nRy.keyframes()
4.設置與獲得DisplayFlag
n = hou.node('/obj/sphere_py01/sphere1')
n.setDisplayFlag(False)
n.isDisplayFlagSet()
n.isObjectDisplayed()
5.設置節點是否可以選擇
n.setSelectableInViewport(False)
# 獲得狀態
n.isSelectableInViewport()
6.設置Xray
n.useXray(True)
n.isUsingXray()
7.Transform
_parent = n.parentAndSubnetTransform()
_pre = n.preTransform()
_parm = n.parmTransform()
_world = n.worldTransform()
_product = _parent * _pre * _parm
print (_product == _world) # True
8.獲得節點當前階段的幾何信息
_geo = hou.node('/obj/sphere1/AddPointNormals').geometry()
# 獲得所有點
_points = _geo.points()
#打印每一個頂點的ID和POS
for p in _points:
_pos = p.position()
print "(%d) -> x=%f, y=%f, z=%f" % (p.number(), _pos[0], _pos[1], _pos[2])
#獲得序號30-39(不包括39),每隔一個的點的集合
_glob = _geo.globPoints('30-39:2')
for p in _glob:
_pos = p.position()
print "(%d) -> x=%f, y=%f, z=%f" % (p.number(), _pos[0], _pos[1], _pos[2])
# 獲得每一個prim的頂點集合
_prims = _geo.prims()
for p in _prims:
_verts = p.vertices()
buff = '('
for i in range(p.numVertices()):
buff += str(_verts[i].point().number()) + ' '
buff += ')'
print "%d) -> %s" % (p.number(), buff)
#將幾何信息存成文件
_geo.saveToFile('C:/Temp/_geo.beo')
#獲得點的屬性
for attr in _geo.pointAttribs():
print attr
9.關鍵幀
n = hou.node('/obj/ball')
nRz = n.parm('rz')
_keys = nRz.keyframes()
_key4 = _keys[3]
_key4.frame()
_key4.time()
_key4.expressionLanguage()
_key4.value()
_key4.slope()
_key4.accel()
#設置關鍵幀
_key4.setExpression('spline()')
_key4.setValue(45)
nRz.setKeyframe(_key4) #一定要執行這裏,否則不會出現結果
10.hou.session
打開Python Source Editor寫入
from hou import *
def popString(inputString = 'FUBAR'):
ui.displayMessage(inputString)
打開Python Shell
hou.session.popString()
hou.session.popString("The life of a DA is always intense")
這樣就會執行在sourceEditor裏寫入的popString的方法
獲得sourceEditor裏的內容
hou.sessionModuleSource()
想sourceEditor裏追加代碼
buff = '\ndef prod(a,b):\n return a*b'
hou.appendSessionModuleSource(buff)
執行之後,如果你打開着SourceEditor,那麼並不好立即看到結果,需要點擊SourceEditor的Reload,在彈出的對話框裏選中OK
如果要覆蓋整個SourceEditor的內容
hou.setSessionModuleSource(buff)
不要忘了reload一下