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

2024-05-15 07:55:12 发布

您现在位置: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:消息属性没有数据值。#在

在本例中,第一个属性是“Message”,没有值。我怎么能绕过这个?在


Tags: 网络属性节点错误attributeattributesprintmash
1条回答
网友
1楼 · 发布于 2024-05-15 07:55:12

您需要处理消息属性,因为错误表明它们没有数据。在

这样你就不会发火了:

import maya.cmds as cmds

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

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

^{pr2}$

相关问题 更多 >