2014-01-06 4 views
1

마야에서 조인트를 선택하고 조인트를 선택하는 동안 사용자가 다음과 같은 인터페이스의 버튼을 누르는 도구에 대한 코드를 작성했습니다. 도구는 단추의 텍스트에 조인트의 이름을 다시 지정해야합니다. 코드가 Maya의 스크립트 편집기에서 컴파일되고 도구 UI가 올바르게 표시됩니다. 그러나 조인트를 선택한 다음 jnt_L_toe 버튼 (현재 작동해야하는 유일한 버튼)을 누르면 조인트 이름이 jnt_L_toe로 대체되지 않습니다. 제 질문에 대한 이유는 무엇입니까?Python 스크립트가 컴파일되지만 마야에서 어떤 동작도 수행하지 않습니다

#Global variable contains all joints in model 
joints_list = maya.cmds.ls(type="joint") 

#Variable names 
Ltoe = "jnt_L_toe" 

# create the window 
wnd_name = maya.cmds.window(title="Rename-A-Joint", widthHeight=[300, 500]) 

# create the layout 
maya.cmds.rowColumnLayout(numberOfColumns = 2, rowSpacing=[(1,5), (2,5)], columnWidth=[(1,120),(2,120)]) 
maya.cmds.text(label="Please select a \n joint then one\n of the following\n buttons to rename it:", font = "boldLabelFont") 
maya.cmds.text(label="    \n         \n      ", font = "boldLabelFont") 

# create the controls 
maya.cmds.text(label="Legs", font = "boldLabelFont") 
maya.cmds.text(label="Hands", font = "boldLabelFont") 
maya.cmds.button(label="jnt_L_toe", command="renameJoint(Ltoe)") 
maya.cmds.button(label="jnt_L_thumb1", command="pass") 
maya.cmds.button(label="jnt_L_ball", command="pass") 
maya.cmds.button(label="jnt_L_thumb2", command="pass") 
maya.cmds.button(label="jnt_L_ankle", command="pass") 
maya.cmds.button(label="jnt_L_thumb3", command="pass") 
maya.cmds.button(label="jnt_L_knee", command="pass") 
maya.cmds.button(label="jnt_L_thumb4", command="pass") 
maya.cmds.button(label="jnt_L_thigh", command="pass") 
maya.cmds.button(label="jnt_L_thumb5", command="pass") 
maya.cmds.text(label="Arms", font = "boldLabelFont") 
maya.cmds.button(label="jnt_L_index1", command="pass") 
maya.cmds.button(label="jnt_L_clavicle", command="pass") 
maya.cmds.button(label="jnt_L_index2", command="pass") 
maya.cmds.button(label="jnt_L_shoulder", command="pass") 
maya.cmds.button(label="jnt_L_index3", command="pass") 
maya.cmds.button(label="jnt_L_elbow", command="pass") 
maya.cmds.button(label="jnt_L_index4", command="pass") 
maya.cmds.button(label="jnt_L_forearm", command="pass") 
maya.cmds.button(label="jnt_L_middle1", command="pass") 
maya.cmds.button(label="jnt_L_wrist", command="pass") 
maya.cmds.button(label="jnt_L_middle2", command="pass") 
maya.cmds.text(label="") 
maya.cmds.button(label="jnt_L_middle3", command="pass") 
maya.cmds.text(label="") 
maya.cmds.button(label="jnt_L_middle4", command="pass") 
maya.cmds.text(label="") 
maya.cmds.button(label="jnt_L_ring1", command="pass") 
maya.cmds.text(label="") 
maya.cmds.button(label="jnt_L_ring2", command="pass") 
maya.cmds.text(label="") 
maya.cmds.button(label="jnt_L_ring3", command="pass") 
maya.cmds.text(label="") 
maya.cmds.button(label="jnt_L_ring4", command="pass") 
maya.cmds.text(label="") 
maya.cmds.button(label="jnt_L_pinky1", command="pass") 
maya.cmds.text(label="") 
maya.cmds.button(label="jnt_L_pinky2", command="pass") 
maya.cmds.text(label="") 
maya.cmds.button(label="jnt_L_pinky3", command="pass") 
maya.cmds.text(label="") 
maya.cmds.button(label="jnt_L_pinky4", command="pass") 

# show the window 
maya.cmds.showWindow(wnd_name) 

#Function to change name of joint 
def renameJoint(name): 
    currentjoint = cmds.ls(type = "joint", selection=True) 
    for connect in joints_list: 
     if(connect == currentjoint): 
      cmds.rename(connect, 'name')` 

답변

1

페이지 당 코드 아무 문제가 없습니다 : 여기

는 코드입니다. 문제는 여러분이 보여준 코드 외부입니다. 파이썬 스 니펫을 가져 와서 가져 오기 문을 생략 할 수는 없습니다. 또한 일반적으로보고 된 오류를 게시해야합니다.

가장 큰 문제는 본문에서와 다른 이름 공간을 사용한다는 것입니다. 당신은 본체에 maya.cmds 사용을 참조하는 당신이 가져온 나타냅니다 : 한편

import maya.cmds 

기능이 표시 CMDS를 사용

까지 유행 관례 일 것입니다
import maya.cmds as cmd 

둘 다 진짜 말이 아니다. 그러나 정말 실종 된 문제로 말하기는 어렵습니다.

def renameJoint(name): 
    currentjoint = cmds.ls(type = "joint", selection=True) 
    for connect in joints_list: 
     if(connect == currentjoint): 
      cmds.rename(connect, 'name')` 

이 아마해야합니다 :

또 다른 오류

는에서 찾을 수 있습니다

def renameJoint(name): 
    currentjoint = cmds.ls(type = "joint", selection=True) 
    for connect in joints_list: 
     if(connect == currentjoint[0]): 
      cmds.rename(connect, name) 

비트 신비하지만 확인합니다. 어쨌든 코드를 다음과 같이 변경하는 것이 좋습니다.

import maya.cmds as cmds 

def renameJoint(name): 
    currentjoint = cmds.ls(type = "joint", selection=True) 
    if currentjoint[0] in joints_list: 
     cmds.rename(currentjoint[0], name) 

def multipleButtonGrp(title,lst): 
    cmds.text(label=title, font = "boldLabelFont") 
    cmds.text(label="") 
    for item in lst: 
     cmds.button(item, label=item, command="renameJoint('%s')"%item) 

joints_list = maya.cmds.ls(type="joint") 

wnd_name = cmds.window(title="Rename-A-Joint", widthHeight=[300, 500]) 

cmds.rowColumnLayout(numberOfColumns = 2) #add your options 
multipleButtonGrp("Hands", 
       ["jnt_L_toe", "jnt_L_thumb1", 
       "jnt_L_ball", "jnt_L_thumb2", 
       "jnt_L_ankle", "jnt_L_thumb3", 
       "jnt_L_knee", "jnt_L_thumb4", 
       "jnt_L_thigh", "jnt_L_thumb5"]) 

cmds.showWindow(wnd_name) 
+0

솔루션을 제공해 주셔서 감사합니다. 그렇습니다. 평범한 오래된 import maya.cmds가 처음에 사용되었습니다 (코드에 포함하는 것을 잊었습니다). 그러나 전체 스크립트는 여전히 renameJoint 함수를 저장하지 않고 실행되었습니다. 여기서 if (connect == currentjoint)라는 행이 문제가되는 부분이었습니다. UI에 대해 더 웅변적인 솔루션을 분명히 제공했습니다. 유일한 문제는 다리와 팔 다음에 빈 버튼이 나타나지 않아야한다는 것입니다. 그래서 수표가 필요합니다. 어쨌든 다시 한번 감사드립니다 - 나는 15 명의 담당자가 없으면 몇 번 답변을 썼습니다. :) – Enchanter

+0

아니요, 답을 받아 들일 수 있고 (체크 표시) 15 점이 있습니다. 게다가 지금 :) – joojaa

관련 문제