python - 在 Maya 中调用函数的按钮

标签 python python-2.7 maya

我正在尝试在函数中创建一个按钮来调用类中的另一个函数。

这就是我所做的:

# button calling functions
import maya.cmds as cmds
import maya.mel as mel
from functools import partial

class B:
    def __init__(self):
        self.create_window()

    def printText(self, text, *args):
        print(text)
        return

    def create_window(self):
        window = cmds.window()
        cmds.rowColumnLayout(numberOfColumns=2, columnWidth=[(1, 50), (1, 70)])
        cmds.text(label='Name')
        axis = cmds.textField()
        cmds.showWindow(window)
        text_entered = cmds.textField(axis, query=True, text=True)
        #cmd = 'printText("{0}")'.format(text_entered)
        cmds.button(label="asd", command = partial(self.printText, text_entered))
        return       

a = B()

问题是我什么也没打印出来。我做错了什么?

最佳答案

找到了一个解决方案,但我觉得有点奇怪

import maya.cmds as cmds

class B:
    def __init__(self):
        self.create_window()

    def create_window(self):
        if cmds.window("UI", exists=True):
            cmds.deleteUI("UI")
        win = cmds.window("UI")
        cmds.columnLayout()
        textEntered = cmds.textField()

        def print_text_contents(a):
            print cmds.textField(textEntered, query=True, text=True)

        cmds.button(label='Confirm', command=print_text_contents)
        cmds.showWindow(win)


B()

关于python - 在 Maya 中调用函数的按钮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45427554/

相关文章:

python - 将圆盘形掩码应用于 NumPy 数组中的多个位置

python - 神经网络似乎在每次执行时都停留在单个输出上

python - 如何跳过在 Django 中创建测试数据库之一

python - 使用 Python 执行 GameFbxExporter Maya

python - ImageChops.difference 的定义

python - 切片端点被无形地截断

python:压缩csv缓冲区

python - 使用单个查询从多个表中提取

python - 在 Maya 中设置对象的大小 - 比例值与精确单位

python - 如何从选择中获取边缘索引?