如何使用Maya python列出一个节点属性的所有值?



我正在尝试列出一个节点的所有属性及其值(来自 Mash 网络(,但是当属性没有值时出现错误,即使我使用 try/except 循环

attributes = cmds.listAttr('MASH_A_Repro')
for attribute in attributes:
myAttr='MASH_A_Repro.'+attribute
try :
print 'Attribute %s Value %s' % (attribute, cmds.getAttr(myAttr) )
except KeyError:
print 'erreur'  
错误:

运行时错误:文件第 10 行:消息属性没有数据值。 #

在这种情况下,第一个属性是"消息",没有值。我怎样才能绕过这个?

你想解决消息属性 - 因为错误说它们没有数据。

这样可以防止您爆炸:

import maya.cmds as cmds
for item in cmds.listAttr('polyPlane1'):
try:
print cmds.getAttr('polyPlane1.' + item)
except RuntimeError:
pass

但是您仍然会收到一个烦人的错误打印输出。您可以通过将listAttr调用限制为可写属性来进行廉价的预检查:

for item in cmds.listAttr('polyPlane1', w=True):
try:
print item, cmds.getAttr('polyPlane1.' + item)
except RuntimeError:
pass

use flag: hasData=True

仅列出具有数据的属性(除消息属性之外的所有属性(

attrsList = cmds.listAttr(camShape, keyable=True, visible=True, hasData=True)

最新更新