Min*_*yen 5 python maxscript pyside
我在3Dsmax 2015上做了一些简单的PySide.
这是我的错误:
python.ExecuteFile "C:\Program Files\Autodesk\3ds Max 2015\scripts\Python\demoUniTest.py"
-- Runtime error: Line 32 <module>()
<type 'exceptions.RuntimeError'> A QApplication instance already exists.
Run Code Online (Sandbox Code Playgroud)
这是我的代码:
import sys
from PySide.QtCore import *
from PySide.QtGui import *
from math import *
class Form(QDialog):
def __init__(self,parent=None):
super(Form,self).__init__(parent)
self.browser = QTextBrowser()
self.lineedit = QLineEdit("Type an expression and press Enter")
self.lineedit.selectAll()
layout = QVBoxLayout()
layout.addWidget(self.browser)
layout.addWidget(self.lineedit)
self.setLayout(layout)
self.lineedit.setFocus()
self.connect(self.lineedit, SIGNAL("returnPressed()"),self.updateUi)
self.setWindowTitle("Calculate")
def updateUi(self):
try:
text = self.lineedit.text()
self.browser.append("%s = <b>%s</b>" % (text,eval(text)))
except:
self.browser.append("<font color=red>%s is invalid</font>" %text)
app = QApplication(sys.argv)
form = Form()
form.show()
app.exec_()
Run Code Online (Sandbox Code Playgroud)
当我在Picharm上使用此代码时,没有任何错误.它仅在我在3Dsmax 2015 Listener上使用时出现
小智 11
直接引用helpfile(使用PySide):
通常,使用QtGui.QApplication()在脚本中创建PySide应用程序对象.但是,在3ds Max中,已经有一个PySide应用程序正在运行,因此您可以获得该对象的句柄,如下所示:
Run Code Online (Sandbox Code Playgroud)QtGui.QApplication.instance()
您正在以下行中创建 QApplication 的实例:
app = QApplication(sys.argv)
Run Code Online (Sandbox Code Playgroud)
之所以出现该错误,是因为在此之前的某处创建了 QApplication 的另一个实例(大概是在“3Dsmax 2015 Listener”中的某处),并且只允许您创建一个实例。
看: