简体   繁体   中英

Maya Python, Renaming joints: more than one object matches name

Ok, so I get two errors whenever I try to run this script: but before I get ahead of myself: lets get to my objective.

create two joint chains, names are unimportant: but essentially I know that you can use brackets to list and isolate joint chains with matching children names. Instead my script seems to be ignoring the brackets and giving me the error anyways. I've tried every different flag for list relatives: but all that seems to do is change the error to something else.

I know that if this script was properly working it would only work on one joint chain because of the hardcoded names: but the script I'm pulling it from has name prefexes tied to the GUI to avoid hardcoding and allow adaptive naming: I'm only using the hardcoded as an example for this script. My complaint is this script doesn't work on ANY joint chain because I keep getting the error "more than one object matches name."

To run the script,save the following code as a.py in your maya documents script folder, restart your copy of maya, then open a new python tab and run the first three lines of code above import maya.cmds

'''
import exampleScriptTemplate
reload (exampleScriptTemplate)
exampleScriptTemplate.gui()
'''

import maya.cmds as cmds

if cmds.window("buildWin", exists =True):
    cmds.deleteUI("buildWin", window = True)

myWindow = cmds.window("buildWin",t='DS_pvFinder',rtf=1,w=100, h=100, toolbox=True)
column = cmds.columnLayout(adj=True)

def gui(*args):
    cmds.columnLayout()
    cmds.button(w=300,label='build placement curve',c=printMultiple)
    cmds.showWindow(myWindow)

def printMultiple(*args):
    
    root = cmds.ls(sl=True)[0]
    child = cmds.listRelatives(root,ad=1,f=True,children=True,type='joint')
    child.append(root)
    child.reverse()
    limbJnt = child

    print (child)

    armroot = []
    for j in limbJnt:
        wstJnt = cmds.rename(child[3], 'wrist_BIND')
        elbJnt = cmds.rename(child[2], 'elbow_BIND')
        sdrJnt = cmds.rename(child[1], 'shoulder_BIND')
        clvJnt = cmds.rename(child[0], 'clavicle_BIND')
        armroot.append(j)

    return armroot

I know I'm in the right ballpark. I just need to know how to properly use the brackets to store the list of what i'm selecting instead of searching all of worldspace and breaking.

Thank you for your help

The code you provided is incomplete, no window is opening, so I tried only the printMultiple function which causes a Error: No object matches name in my case.

Your code cannot work like this since you mix hardcoded names with a loop which does nothing. I suppose your main problem is the order of your renamings. The child array contains absolute names like:

[u'joint1', u'|joint1|joint2', u'|joint1|joint2|joint3']

If you now rename child[0] to 'clavicle_BIND', all the remaining elements in the list become invalid because their real names in the scene now look like this:

[u'clavicle_BIND', u'|clavicle_BIND|joint2', u'|clavicle_BIND|joint2|joint3']

What results in an error at the second rename line. Inverting the order sovles this problem, first rename the leaf node, then the ones above.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM