【问题标题】:Pymel TypeError: file <maya console>Pymel TypeError:文件 <maya 控制台>
【发布时间】:2015-09-09 14:07:41
【问题描述】:

我正在尝试选择一个对象并显示行编辑

从 PySide 导入 * 从 pymel 导入 *
将 pymel.core 导入为 pm 将 maya.cmds 导入为 cmds 将 maya.mel 导入为 mel 将 maya.OpenMaya 导入为 OpenMaya

def select_obj(obj):
    list = pm.poly
print obj

button = QPushButton("select")
button.clicked.connect(select_obj)
button.show()

def desselect_obj(obj):
    list = OpenMaya.MSelection()
print obj

button2 = QPushButton("disconnect")
button2.clicked.connect(select_obj)
button2.show()


edit = QLineEdit(nome)
QLineEdit.show(select_obj)
label.show()

app.exec_()

# Error: line 1: TypeError: file <maya console> line 25: 'PySide.QtGui.QLineEdit' called with wrong argument types:
  PySide.QtGui.QLineEdit(function)
Supported signatures:
  PySide.QtGui.QLineEdit(PySide.QtGui.QWidget = No`enter code here`ne)
  PySide.QtGui.QLineEdit(unicode, PySide.QtGui.QWidget = None) # 
# TypeError: select_obj() takes exactly 1 argument (0 given)

【问题讨论】:

  • 这段代码真的没有任何意义,你能发布更正的版本吗?

标签: for-loop maya mel pymel


【解决方案1】:

您的代码有很多问题。您不需要导入那么多模块(尤其是未使用的模块)。通常,在使用 PySide 创建 ui 时,您会包装一个继承自 QWidgetQMainWindow 的类。看看下面的代码,它是一个带有按钮和 lineEdit 的窗口的简单示例。当您按下按钮时,它会将所选对象的名称添加到 lineEdit。

from PySide import QtGui, QtCore
import maya.cmds as cmds

class Window(QtGui.QWidget):
    def __init__(self, parent = None):
        super(Window, self).__init__(parent) # Inherit from QWidget

        # Create button
        self.button = QtGui.QPushButton("select")
        self.button.clicked.connect(self.select_obj)

        # Create line edit
        self.edit = QtGui.QLineEdit()

        # Create widget's layout
        mainLayout = QtGui.QVBoxLayout()
        mainLayout.addWidget(self.button)
        mainLayout.addWidget(self.edit)
        self.setLayout(mainLayout)

        # Resize widget, and show it
        self.resize(200, 200)
        self.show()

    # Function to add selected object to QLineEdit
    def select_obj(self):
        sel = cmds.ls(sl = True) # Get selection
        if sel:
            self.edit.setText(sel[0]) # Set object's name to the lineEdit

win = Window() # Create instance of the class

【讨论】:

    猜你喜欢
    • 2018-05-04
    • 1970-01-01
    • 2022-06-30
    • 1970-01-01
    • 1970-01-01
    • 2022-09-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多