maya 独立与 pyside2
Posted
技术标签:
【中文标题】maya 独立与 pyside2【英文标题】:maya standalone with pyside2 【发布时间】:2021-06-21 05:28:45 【问题描述】:当我想在独立的 Maya 中添加 QtWidget 时,错误提示“QWidget:无法在没有 QApplication 的情况下创建 QWidget”。
from PySide2 import QtWidgets
import maya.standalone
maya.standalone.initialize()
QtWidgets.QPushButton()
maya.standalone.uninitialize()
然后我添加了一个 QApplication,错误提示:“一个 QApplication 实例已经存在。”
from PySide2 import QtWidgets
import maya.standalone
import sys
maya.standalone.initialize()
QtWidgets.QApplication(sys.argv)
QtWidgets.QPushButton()
maya.standalone.uninitialize()
我使用QApplication.instance()
我可以获得“QGuiApplication”参考,所以
我知道 maya.standalone() 将创建 qApp,但是如何创建 QWidget(例如 s 对话框...)
================================================ =================
from PySide2 import QtWidgets
import maya.standalone
maya.standalone.initialize()
print(QtWidgets.QApplication.instance())
maya.standalone.uninitialize()
这是完整的日志:
pymel.core : INFO : Updating pymel with pre-loaded plugins: renderSetup
Warning: file: C:/Program Files/Autodesk/Maya2018/scripts/startup/initialStartup.mel line 179: Y-axis is already the Up-axis
Warning: file: C:\Users\a\Documents\maya\2018\prefs\filePathEditorRegistryPrefs.mel line 4: filePathEditor: Attribute 'aiImage.filename' is invalid or is not designated 'usedAsFilename'.
Warning: file: C:\Users\a\Documents\maya\2018\prefs\filePathEditorRegistryPrefs.mel line 5: filePathEditor: Attribute 'aiPhotometricLight.aiFilename' is invalid or is not designated
'usedAsFilename'.
Warning: file: C:\Users\a\Documents\maya\2018\prefs\filePathEditorRegistryPrefs.mel line 6: filePathEditor: Attribute 'aiStandIn.dso' is invalid or is not designated 'usedAsFilename'.
Warning: file: C:\Users\a\Documents\maya\2018\prefs\filePathEditorRegistryPrefs.mel line 7: filePathEditor: Attribute 'aiVolume.filename' is invalid or is not designated 'usedAsFilename'.
AbcExport v1.0 using Alembic 1.7.5 (built Feb 6 2018 18:28:08)
Initialized VP2.0 renderer
Version : 2016.11.40.12. Feature Level 5.
Adapter : GeForce RTX 3090/PCIe/SSE2
Vendor ID: 4318. Device ID : 8708
Driver : .
API : OpenGL V.4.6.
Max texture size : 16384 * 16384.
Max tex coords : 32
Shader versions supported (Vertex: 5, Geometry: 5, Pixel 5).
Shader compiler profile : (Best card profile)
Active stereo support available : 0
GPU Memory Limit : 24576 MB.
CPU Memory Limit: 62178.5 MB.
MultiDraw consolidation: enabled
OpenCL evaluator is attempting to initialize OpenCL.
Detected 1 OpenCL Platforms:
0: NVIDIA Corporation. NVIDIA CUDA. OpenCL 1.2 CUDA 11.2.162.
Supported extensions: cl_khr_global_int32_base_atomics cl_khr_global_int32_extended_atomics cl_khr_local_int32_base_atomics cl_khr_local_int32_extended_atomics cl_khr_fp64 cl_khr_byte_addressable_store cl_khr_icd cl_khr_gl_sharing cl_nv_compiler_options cl_nv_device_attribute_query cl_nv_pragma_unroll cl_nv_d3d10_sharing cl_khr_d3d10_sharing cl_nv_d3d11_sharing cl_nv_copy_opts cl_nv_create_buffer cl_khr_int64_base_atomics cl_khr_int64_extended_atomics cl_khr_device_uuid
OpenCL evaluator choosing OpenCL platform NVIDIA Corporation.
OpenCL evaluator is unable to find a GPU device that can share VBOs with OpenGL.
Warning: file: C:/Program Files/Autodesk/Maya2018/scripts/startup/autoLoadPlugin.mel line 35: Loading plug-in "lookdevKit" has resulted in changes to the scene that may need to be saved.
AbcImport v1.0 using Alembic 1.7.5 (built Feb 6 2018 18:28:08)
<PySide2.QtGui.QGuiApplication object at 0x000001828E9D9108>
【问题讨论】:
print(QApplication.instance())
的输出是什么?显示完整的日志消息
我在帖子中添加了完整的日志
如果在maya.standalone.initialize()
之前添加QtWidgets.QApplication(sys.argv)
会得到相同的日志吗?
是的,它可以工作,在 maya.standalone.initialize() 创建 Qapp 并加载我的 Qt UI 类,实例化 UI 之前。 maya.standalone.initialize() 完成maya代码作业后,弹出UI窗口。
【参考方案1】:
如果没有先前的 QXApplication,initialize()
函数会创建一个 QGuiApplication,因此一种可能的方法是在调用该函数之前创建一个 QApplication:
app = QtWidgets.QApplication(sys.argv)
maya.standalone.initialize()
【讨论】:
以上是关于maya 独立与 pyside2的主要内容,如果未能解决你的问题,请参考以下文章