我仍然在弄清楚Python和Maya是如何一起工作的,所以请原谅我的无知。因此,我试图使用这样的循环来更改玛雅关节列表的属性:
for p in jointList: cmd.getAttr(p, 'radius', .5)
我得到了一个错误:
Invalid argument 1, '[u'joint1']'. Expected arguments of type ( list, )
我不知道我做错了什么。
发布于 2016-08-05 16:51:42
除非您使用pyMel,否则您需要指定要获取或设置的attr名称和节点。
for getAttr :
for p in jointList:
val = cmd.getAttr('%s.radius' % (p))for setAttr :
for p in jointList:
cmd.setAttr('%s.radius' % (p), .5)发布于 2016-08-05 14:20:25
您需要同时指定节点和通道作为第一个参数,比如'joint1.radius‘。
要在所有关节上将半径设置为.5,您的代码如下:
for p in jointList:
cmd.setAttr(p + '.radius', .5)发布于 2016-10-19 15:51:59
参考文档中的示例:
http://help.autodesk.com/cloudhelp/2017/ENU/Maya-Tech-Docs/CommandsPython/getAttr.html http://help.autodesk.com/cloudhelp/2017/ENU/Maya-Tech-Docs/CommandsPython/setAttr.html
当将对象名称和属性传递到getAttr()函数时,需要将其指定为字符串。
例如:
translate = cmds.getAttr('pSphere1.translate')将返回pSphere1上转换的属性值。
或
jointList = cmds.ls(type='joint')
for joint in jointList:
jointRadius = cmds.getAttr('{}.radius'.format(joint))
#Do something with the jointRadius below如果你想设置它
newJointRadius = 20
jointList = cmds.ls(type='joint')
for joint in jointList:
cmds.setAttr('{}.radius'.format(joint), newJointRadius)https://stackoverflow.com/questions/38779640
复制相似问题