マヤのPython:名前の変更は、関節の子供を重複

Dasteel:

私は私の自動リギングスクリプトを構築し続けているので、私は解決が困難になると予想三つの問題の第二のうちに実行しました。これはおそらく、本当に単純な答えですが、スクリプト自体は非常に使いやすいです、最初のヒットがプロキシロケータ、そしてヒットビルド脊椎の関節を生成しますが、問題はビルドIKコントロールボタンで入って来、それがバインドされた関節が十分に複製し、最初のものの名前を変更します。しかし、私はそれがバインドされた関節のような適切数の増加があることを得るカント:あなたはそれを展開する場合、それはあなたに任意のヘルプが常に高く評価され「spine__IK」という名前の子供を与えます:

'''
import DS_hybrid_spineOmatic_V1
reload (DS_hybrid_spineOmatic_V1)
DS_hybrid_spineOmatic_V1.gui()
'''

import re
import maya.cmds as cmds
import maya.mel as mel

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

myWindow = cmds.window("spineWin",t='DS_hybrid_spineOmatic_V1',w=200, h=500, toolbox=True)
column = cmds.columnLayout(adj=True)

'''
To DO:
    -You're going to have a series of scrips splitting into an IKFK spine and a ribon spine: this script will build the IKFK spine
    -make build spine joints orient joint chain
'''

def gui():

    cmds.button( label="Generate Spine Proxy Locators", c = buildProxies)
    cmds.separator( w=200, h=3)
    cmds.button( label="Build Spine Joints", c = buildJointChain)
    cmds.separator( w=200, h=3)
    cmds.button( label="Build IK Controls", c = createIKcontrols)
    cmds.separator( w=200, h=9)

    cmds.setParent('..')
    cmds.showWindow(myWindow)

def buildProxies(*args):
    locAmount = 2
    for i in range(locAmount):
        countLoc = i+1
        spaceLoc = cmds.spaceLocator(n = 'spineLoc_{}_PRX'.format(countLoc), p = [0,i*2.5,0])
        cmds.makeIdentity(spaceLoc, a=1, t=1)
        mel.eval('CenterPivot;')

    cmds.parent('spineLoc_2_PRX','spineLoc_1_PRX')

def buildJointChain(*args):

    cmds.select(cl=True) #this line clears your selection

    #this For in range loop creates equidistant joints between the 2 proxy locators
    #//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    countJnt = 7

    startLoc = "spineLoc_1_PRX" #this is where the joint chain starts
    endLoc = "spineLoc_2_PRX" #this is where the joint chain ends

    jntPosSteps = 1.0/(countJnt-1) # Will use count to calculate how much it should increase percentage by each iteration. Need to do -1 so the joints reach both start and end points.
    jntPerc = 0  # This will always go between a range of 0.0 - 1.0, and we'll use this in the constraint's weights.

    for jNum in range(countJnt):
        jntInc = jNum
        jnt = cmds.joint(n = 'spineJnt_{}_Bound'.format(jntInc))
        cmds.setAttr(jnt + ".displayLocalAxis", True) #display the local rotation axis of the joint

        jntConstraint = cmds.pointConstraint(startLoc, jnt, weight=1.0 - jntPerc)[0] # Apply 1st constraint, with inverse of current percentage.
        cmds.pointConstraint(endLoc, jnt, weight=jntPerc)
        cmds.delete(jntConstraint) #constraint is now no longer neccisary

        jntPerc += jntPosSteps #Increase percentage for next iteration
    #//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    #this will orient the joint chain(build later)
    #//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

    #//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    cmds.select(cl=True)
    cmds.group(n='skeletonGrp',empty=True,world=True)
    cmds.parent('spineJnt_0_Bound','skeletonGrp')
    cmds.delete('spineLoc_1_PRX')

def createIKcontrols(*args):

    #create spine control curves
    #//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

    #//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

    #create duplicate joint chain
    #//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    ikName = 'spineJnt_*_IK'
    ikChain = cmds.duplicate('spineJnt_0_Bound', n='spineJnt_0_IK')[0]
    cmds.parent(ikChain,world=True)
    ikList = cmds.listRelatives(ikChain,ad=True,pa=True)
    for name in ikList:
        cmds.rename(name, ikName)
        print(ikList)
    #//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

    #create IK spline handle for joint chain

私はちょうど適切に順次重複ジョイントチェーンの名前を変更するスクリプトが必要

haggi krey:

あなたは、名前を変更するために、ワイルドカードを使用することはできませんcmds.rename(name, ikName)マヤAに*無効な文字であるとアンダースコアで置き換えられますので、「spineJnt___IK」になりますikNameは「spineJnt _ * _ IK」です。しかし、あなたはこれを行うことができます:

for idx, name in enumerate(ikList):
    cmds.rename(name, 'spineJnt_{0}_IK'.format(idx))
    print(ikList)

何多かれ少なかれ、適切な命名での結果。ここでの問題はlistRelativesは、最初に親のものの前にあなたのリーフノードを与えるということです。あなたの番号が逆になりますので。これは、IDを反転させて固定することができます。

cmds.rename(name, 'spineJnt_{0}_IK'.format(len(ikList) - idx))

これはあなたに良い結果を与える必要があります。

おすすめ

転載: http://43.154.161.224:23101/article/api/json?id=26649&siteId=1