如何在Maya中查看节点的所有属性?

时间:2015-06-16 21:51:43

标签: python nodes maya

我试图通过代码更新Maya中的某些属性值,而且我很难访问它们。

我需要显示名称的属性,(我很确定这应该是他们的好名字'),但我似乎无法以任何方式获取它们。使用listAttr或使用OpenMaya的MFnAttribute都不能给我我想要的东西 - 他们传回长名和短名称并清理好名字'但这些都不是显示属性的UI名称。

作为一个例子,我的节点包含一个名为' Horizo​​ntal Damping Factor'标题为“高级锚点控制”的下拉列表。'当我在节点中查询属性名称列表时,我得到了类似的名称' Anchor HDamping Factor',但这不是显示的名称。对于其他23个属性也是如此。

您对正在发生的事情有任何想法吗?

(所有这些属性都位于两个下拉列表的字段中,这是一个问题吗?)

编辑:这肯定是因为属性是两个下拉深度...我仍然不知道这些下拉列表被调用或如何访问其中包含的属性。

编辑2:嗯,我错了,属性的名称与显示的名称不同(当我调整滑块时,编辑器窗口显示我刚刚更改的值的名称,这是与显示的名称不同,它不仅仅是它的名称版本。)仍然试图解决这个问题。

编辑3:不确定这是多么清楚,但它显示了属性的UI标签与“好名字”之间的差异。'没有“水平阻尼因子”#39;在属性名称列表中。 Nice Name and display name discrepancy

最终编辑:如果属性在创建时被赋予了不同的UI名称和权威名称,则通过查询UI名称看起来无法更改属性的值。在代码中创建了我自己的映射。

2 个答案:

答案 0 :(得分:2)

如果您知道相关属性的attributeQuery及其所属节点的名称,则可以将longNameshortNameniceNameimport maya.cmds as cmds def printAttributes(node, like=''): ''' Convinience function to print all the attributes of the given node. :param: node - Name of the Maya object. :param: like - Optional parameter to print only the attributes that have this string in their nice names. ''' heading = 'Node: %s' % node # Let's print out the fancy heading print print '*' * (len(heading)+6) print '** %s **' % heading print '*' * (len(heading)+6) # Let's get all the attributes of the node attributes = cmds.listAttr(node) # Let's loop over the attributes now and get their name info for attribute in attributes: # Some attributes will have children. (like publishedNodeInfo) # We make sure we split out their parent and only use the child's name # because attributeQuery cannot handle attributes with the parentName.childName format. attribute = attribute.split('.')[-1] # Let's now get the long name, short name # and nice name (UI name) of the atribute. longName = cmds.attributeQuery(attribute, node=node, longName=True) shortName = cmds.attributeQuery(attribute, node=node, shortName=True) niceName = cmds.attributeQuery(attribute, node=node, niceName=True) # if we the 'like' parameter has been set, we'll check if # the nice name has that string in it; # else we skip this attribute. if like and like.lower() not in niceName.lower(): continue # Now that we have all the info we need, let's print them out nicely heading = '\nAttribute: %s' % attribute print heading print '-' * len(heading) print 'Long name: %s\nShort name: %s\nNice name: %s\n' % (longName, shortName, niceName) if __name__ == '__main__': # Let us get a list of selected node(s) mySelectedNodes = cmds.ls(sl=True) # Let us do the printAttributes() for every selected node(s) for node in mySelectedNodes: # Just for example, just printing out attributes that # contain the word 'damping' in their nice (UI) name. printAttributes(node, like='damping') 分别获得它的长名,短名和好名字。

根据我对您的问题的理解,您希望能够查看节点的所有属性的这些信息,以便您可以正确决定选择哪个属性来执行您正在执行的操作。这是我写的一个快速脚本,一个简单的查询,给你这样的:(慷慨地散布作为评论的解释)

listAttr()

请注意,我们使用命令attributeInfo()来获取节点的所有属性的列表。请注意,我们也可以使用attributeInfo()来获取属性列表。 listAttr()优于attributeInfo()的优势在于{{1}}具有更多过滤器标记,可根据属性的各种参数和属性过滤掉列表。

值得查看以下文档: attributeQuery attributeInfo listAttr

答案 1 :(得分:2)

权威名称是listAttr中的名称;您在UI中看到的名称不可靠,因为AETemplate可以以任何方式覆盖它们。 AE经常呈现用于计算实际值的虚假属性 - 例如,相机在属性编辑器中有angleOfView,但设置它实际上会更改focalLength属性;相机节点上没有angleOfView

因此,您可能需要做一些侦探工作来弄清楚可见用户界面的确在做什么。玩滑块和观看历史是通常的第一步。

FWIW

 dict(zip(cmds.listAttr(), cmds.listAttr(sn=True)))

将为您提供一个字典,将长名称映射到短名称,这样可以使事情更具可读性。