Houdini With Python学习记(CHAO)录(XI)02

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一下

 

  • 5
    点赞
  • 19
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值