python - 如何使用 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'
错误:RuntimeError:文件第 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
推荐阅读
- git - 如何每天从 gerrit 服务器获取精心挑选的提交 ID
- node.js - 如何使用 NodeJS 和 JSON.stringify() 创建 JSON 嵌套对象
- c# - How to Get File using Console application in C#?
- python - 如何写几个图像而不重叠
- python - Python 2.7.13 是否与 Python 2.7.16 兼容?一般来说,Python 2.7.1X 是否相互兼容?
- python-3.x - 试图抓取并分离成标题和内容。问题是两者都有相同的类和标签,如何隔离?
- asp.net - 在网格视图 TemplateField 中处理特殊字符“/”
- powershell - 如何在 powershell 中使用 VSTEST.CONSOLE.EXE 运行 mstest
- java - Java HashMap 内部数据结构在 rehash 期间如何变化?
- java - 在 Seam 项目中使用模拟服务