【问题标题】:How to see all attributes of a node in Maya?如何在 Maya 中查看节点的所有属性?
【发布时间】:2015-06-16 21:51:43
【问题描述】:

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

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

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

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

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

编辑:这绝对是因为属性是两个下拉菜单...我仍然不知道这些下拉菜单被称为什么或如何访问其中包含的属性。

编辑2:好吧,我错了,属性的名称与显示的名称不同,(当我调整滑块时,编辑器窗口显示我刚刚更改的值的名称,这与显示的不同名称,它也不仅仅是它的“好”名称版本。)仍在试图弄清楚这一点。

编辑 3:不确定这有多清楚,但它显示了属性的 UI 标签和“好名”之间的差异。属性名称列表中没有“水平阻尼系数”。

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

【问题讨论】:

    标签: python nodes maya


    【解决方案1】:

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

    因此,您可能需要做一些侦探工作来弄清楚可见 UI 到底在做什么。使用滑块并查看历史是通常的第一步。

    FWIW

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

    将为您提供一个将长名称映射到短名称的字典,这可以方便地使内容更具可读性。

    【讨论】:

    • 哈哈,我知道你最终会加入@Theodox。我肯定会为显示的名称及其实际名称创建地图。似乎是 Maya 的一个缺陷,即使我自己拥有节点/属性,我也无法获得那些 UI 可见的属性名称。
    • 很烦人,但是关于 AEtemplates 的一切都很烦人'
    【解决方案2】:

    如果您知道相关属性的longName 及其所属节点的名称,则可以将attributeQuery 与longName、shortName 或niceName 一起使用以获得它的长分别是名字、简称和好听的名字。

    根据我从您的问题中了解到的情况,您希望能够查看节点所有属性的所有这些信息,以便您可以正确决定选择哪个属性来执行您正在做的事情。这是我写的一个快速脚本,一个简单的查询,只是为了给你:(慷慨地穿插解释为 cmets)

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

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

    【讨论】:

    • 感谢您的资源!可悲的是,这是我的问题;我可以获得属性的长、短和漂亮的名称,但我需要的是显示给用户的文本。通常 Maya 只会显示好听的名称,但如果您在创建属性时为其指定自定义名称,则无法查询该名称。我将更新示例以帮助解释这一点。
    • 使用示例更新以使您的问题更清楚。同时,我更新了我的答案,提供了更多细节。
    • 另外,据我了解,“Nice Name”是在 UI 中显示给用户的名称。你验证了吗?如果不是,请给我另外的情况。
    • worldRotatePivot 是从 rotatePivot 计算出来的,它不是它自己的属性
    • cmds.xform('object', piv = (0,0,0), a=True, ws=True)(当然是你的名字和电话号码)
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-09-12
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多