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

2024-10-01 15:36:43 发布

您现在位置:Python中文网/ 问答频道 /正文

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

我需要属性显示名称(我很确定这应该是它们的“好名字”),但我似乎无法以任何方式获取它们。使用listAttr或OpenMaya的mfnatAttribute都不能满足我的需要—它们会传回长名称和短名称,并清理“好名字”,但这些都不是属性的显示UI名称。在

例如,我的节点在一个名为“高级锚点控制”的下拉列表中包含一个名为“水平阻尼因子”的属性。当我在节点中查询属性的友好名称列表时,我得到了类似的名称“Anchor HDamping Factor”,但这不是显示的名称。其他23个属性也是如此。在

你对发生的事有什么想法吗?在

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

编辑:这肯定是因为属性是两个下拉的深度。。。我仍然不知道这些下拉列表的名称,也不知道如何访问其中包含的属性。在

编辑2:好吧,我错了,属性的名称与显示的名称不同,(当我调整滑块时,编辑器窗口会显示我刚更改的值的名称,这与显示的名称不同,而且它也不仅仅是一个“漂亮”的名称版本。)仍在试图解决这个问题。在

编辑3:不确定这有多清楚,但它显示了属性的UI标签和“Nice Name”之间的差异。属性名称列表中没有“Horizontal Damping Factor”。 Nice Name and display name discrepancy

最终编辑:似乎不可能通过查询UI名称来更改属性的值,如果属性的UI名称不同于创建时的权威名称。而是在代码中创建了自己的映射。


Tags: 代码名称编辑ui列表属性节点方式
2条回答

如果您知道相关属性的longName以及它所属节点的名称,则可以将attributeQuerylongNameshortNameniceName一起使用,分别获得它的长名称、短名称和友好名称。在

根据我对您问题的理解,您希望能够查看节点所有属性的所有这些信息,以便您能够正确地决定选择哪个属性来执行您正在执行的操作。这是我写的一个简短的脚本,一个简单的查询,给你的就是:(大量地穿插着解释作为注释)

import 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()相比,attributeInfo()的优势在于,attributeInfo()有更多的过滤标志,可以根据属性的各种参数和属性筛选出列表。在

值得去查看以下文件: attributeQueryattributeInfolistAttr

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

因此,您可能需要做一些调查工作,以找出可见UI的真正用途。通常的第一步是玩滑块,看历史。在

FWIW公司

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

会给你一个字典,把长的名字映射到短的名字,这样可以方便地让东西更容易阅读。在

相关问题 更多 >

    热门问题