Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
121 views
in Technique[技术] by (71.8m points)

python 2.7 - import Qt ui to Maya2020

Last week I started learning Python for Maya, following the 'CGCircuit - Learn Python Inside Maya'. Now I'm trying to make a simple UI for Maya2020 using Qt. The tutorial itself is pretty outdated, a lot has changed since Maya2015. I checked a lot of forums and it seems I’m not the only one having problems. This is what I learned so far:

  • Qt designer is not a part of Maya anymore, so I downloaded Qt Creator 4.14.0 (Community)
  • I used pip to install: shiboken2-5.15.2-5.15.2-cp35.cp36.cp37.cp38.cp39-none-win_amd64.whl
  • If I'm correct, Maya2020 has Pyside2 pr-installed, but I also Installed Pyside2 on Windows10
  • QtGui.QDialog is replaced by QWidget Currently I ‘m using Python 2.7.17 on my Windows system, but I also have Python3.8 available in my Environment Variable

When I call the py script inside Maya, like this:

import geomGenerator
reload(geomGenerator)
geomGenerator.getMayaWindow()

geomGenerator.run()

I get this error:

 Error: NameError: file C:/Users/12213119/Documents/maya/2020/scriptsgeomGenerator.py line 12: global name 'shiboken2' is not defined #

Not sure what this means or how I can solve it. I looked all over the internet, please let me know what I'm doing wrong. Thx in regard.

from PySide2 import QtGui, QtCore, QtUiTools, QtWidgets
from shiboken2 import wrapInstance

import maya.cmds as mc
import maya.OpenMayaUI as omui

def getMayaWindow():
    """ pointer to the maya main window  
    """
    ptr = omui.MQtUtil.mainWindow()
    if ptr is not None:
        return shiboken2.wrapInstance2(long(ptr), QtWidgets.QWidget)


def run():
    """  builds our UI
    """
    global win
    win = GeometryGenerator(parent=getMayaWindow())
    win.show()

class GeometryGenerator(QtWidgets.QWidget):

    def __init__(self,parent=None):
        super(GeometryGenerator,self).__init__(parent)
question from:https://stackoverflow.com/questions/65858944/import-qt-ui-to-maya2020

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

I guess you need to run you script with python that comes with Maya, and use pip that comes with maya to install packages.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...