首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >Python脚本将编译但不执行玛雅的任何操作。

Python脚本将编译但不执行玛雅的任何操作。
EN

Stack Overflow用户
提问于 2014-01-06 04:59:55
回答 1查看 581关注 0票数 1

我已经为一个工具写了一段代码,当在maya中选择一个连接时,当这个连接被选择时,用户在工具的界面上按下一个按钮,它应该将连接重新命名为按钮的文本。代码在maya的脚本编辑器中编译,工具UI显示正确。但是,当您选择一个连接,然后按下jnt_L_toe按钮(目前应该工作的唯一一个),联合名称不会被jnt_L_toe取代,我的问题是为什么?

以下是代码:

代码语言:javascript
运行
复制
#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')`
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2014-01-06 15:36:07

每看一遍代码都没有问题。这就是你所显示的代码之外的问题。您不能真正使用python片段而忽略import语句,因为这些语句是故事的核心内容。此外,您还应该在一般张贴报告的错误。

最可能的问题是,您在函数中使用的命名空间与在您的身体中使用的名称空间不同。请参见在主体中使用maya.cmds,这表明您已经导入了:

代码语言:javascript
运行
复制
import maya.cmds

另一方面,该函数使用cmds,表示:

代码语言:javascript
运行
复制
import maya.cmds as cmd

到目前为止,这是普遍的惯例,两者都做没有真正的意义。然而,很难说出你真正缺失的问题。

另一个错误可以在以下文件中找到:

代码语言:javascript
运行
复制
def renameJoint(name):
    currentjoint = cmds.ls(type = "joint", selection=True)
    for connect in joints_list:
        if(connect == currentjoint):
            cmds.rename(connect, 'name')`

这可能应该是:

代码语言:javascript
运行
复制
def renameJoint(name):
    currentjoint = cmds.ls(type = "joint", selection=True)
    for connect in joints_list:
        if(connect == currentjoint[0]):
            cmds.rename(connect, name)

有点神秘但确定。无论如何,我建议您将代码更改为:

代码语言:javascript
运行
复制
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)
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/20943263

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档