Discussion:
[Maya-Python] need help with this error.
jettam
2017-10-17 04:39:11 UTC
Permalink
When I run this code I get this error. Could someone help me figure this
error out.
Its part of a video tutorial series that explains how to load UI's

# Error: name '__file__' is not defined
# Traceback (most recent call last):
# File "<maya console>", line 1, in <module>
# NameError: name '__file__' is not defined #

import os
from PySide2 import QtWidgets, QtCore, QtUiTools, QtGui
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:
return wrapInstance(long(ptr), QtWidgets.QMainWindow)

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

class GeometryGenerator(QtWidgets.QDialog):

def __init__(self,parent=None):
super(GeometryGenerator,self).__init__(parent)
loader = QtUiTools.QUiLoader()
currentDir = os.path.dirname(__file__)
print("currentDir: {0}".format(currentDir))
currentDir = os.path.dirname(__file__)
print("currentDir: {0}".format(currentDir))
--
You received this message because you are subscribed to the Google Groups "Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_maya+***@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/18922585-840e-4ad7-ba40-9a695cd8d4af%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Justin Israel
2017-10-17 08:56:56 UTC
Permalink
Post by jettam
When I run this code I get this error. Could someone help me figure this
error out.
Its part of a video tutorial series that explains how to load UI's
# Error: name '__file__' is not defined
# File "<maya console>", line 1, in <module>
# NameError: name '__file__' is not defined #
import os
from PySide2 import QtWidgets, QtCore, QtUiTools, QtGui
from shiboken2 import wrapInstance
import maya.cmds as mc
import maya.OpenMayaUI as omui
''' pointer to the maya main window '''
ptr = omui.MQtUtil.mainWindow()
return wrapInstance(long(ptr), QtWidgets.QMainWindow)
''' builds our UI '''
global win
win = GeometryGenerator(parent=getMayaWindow())
win.show()
super(GeometryGenerator,self).__init__(parent)
loader = QtUiTools.QUiLoader()
currentDir = os.path.dirname(__file__)
print("currentDir: {0}".format(currentDir))
currentDir = os.path.dirname(__file__)
print("currentDir: {0}".format(currentDir))
How are you going about executing this code? Are you doing it from an
imported module on your PYTHONPATH, or from within your Script Editor? If
it is from the script editor, then the magic __file__ variable won't be
set, as there is no file; just evaluated code.
Post by jettam
--
You received this message because you are subscribed to the Google Groups
"Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an
To view this discussion on the web visit
https://groups.google.com/d/msgid/python_inside_maya/18922585-840e-4ad7-ba40-9a695cd8d4af%40googlegroups.com
<https://groups.google.com/d/msgid/python_inside_maya/18922585-840e-4ad7-ba40-9a695cd8d4af%40googlegroups.com?utm_medium=email&utm_source=footer>
.
For more options, visit https://groups.google.com/d/optout.
--
You received this message because you are subscribed to the Google Groups "Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_maya+***@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/CAPGFgA1-Pqe5eCYfqeug7kd4mxor%3DP-yKvVZ%3DrJc%3D8%2Bw4cu4GA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.
jettam
2017-10-17 18:49:11 UTC
Permalink
Aha! Yes I was trying to run it from the script editor. It now works if I
run it from a module. Thanks.
Post by Justin Israel
Post by jettam
When I run this code I get this error. Could someone help me figure this
error out.
Its part of a video tutorial series that explains how to load UI's
# Error: name '__file__' is not defined
# File "<maya console>", line 1, in <module>
# NameError: name '__file__' is not defined #
import os
from PySide2 import QtWidgets, QtCore, QtUiTools, QtGui
from shiboken2 import wrapInstance
import maya.cmds as mc
import maya.OpenMayaUI as omui
''' pointer to the maya main window '''
ptr = omui.MQtUtil.mainWindow()
return wrapInstance(long(ptr), QtWidgets.QMainWindow)
''' builds our UI '''
global win
win = GeometryGenerator(parent=getMayaWindow())
win.show()
super(GeometryGenerator,self).__init__(parent)
loader = QtUiTools.QUiLoader()
currentDir = os.path.dirname(__file__)
print("currentDir: {0}".format(currentDir))
currentDir = os.path.dirname(__file__)
print("currentDir: {0}".format(currentDir))
How are you going about executing this code? Are you doing it from an
imported module on your PYTHONPATH, or from within your Script Editor? If
it is from the script editor, then the magic __file__ variable won't be
set, as there is no file; just evaluated code.
Post by jettam
--
You received this message because you are subscribed to the Google Groups
"Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an
To view this discussion on the web visit
https://groups.google.com/d/msgid/python_inside_maya/18922585-840e-4ad7-ba40-9a695cd8d4af%40googlegroups.com
<https://groups.google.com/d/msgid/python_inside_maya/18922585-840e-4ad7-ba40-9a695cd8d4af%40googlegroups.com?utm_medium=email&utm_source=footer>
.
For more options, visit https://groups.google.com/d/optout.
--
You received this message because you are subscribed to the Google Groups "Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_maya+***@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/d508fa3b-8da9-4f0d-97d6-4c61a4d4223c%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
jettam
2017-10-17 18:52:29 UTC
Permalink
I have another error.

This is my code:
import os
from PySide2 import QtWidgets, QtCore, QtUiTools, QtGui
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:
return wrapInstance(long(ptr), QtWidgets.QMainWindow)

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

uiFilePath = os.path.join( os.path.dirname(__file__) ,
'geomGenerator_v001.ui')

class GeometryGenerator(QtWidgets.QDialog):

def __init__(self,parent=None):
super(GeometryGenerator,self).__init__(parent)

loader = QtUiTools.QUiLoader()
print('uiFilePath: {0}'.format(uiFilePath))
xfile = QtCore.QFile(uiFilePath)
xfile.open(QtCore.QFile.ReadOnly)
self.ui = loader.load(file, parentWidget=self)
xfile.close()
layout = QtGui.QVBoxLayout()
layout.addWidget(myWidget)
self.setLayout(layout)

This is the Error:
geomGenerator.run()
uiFilePath: E:\ProfessionalDevelopment\python\Introduction to Python
Scripting in Maya\cgcircuitPython\wk6\geomGenerator_v001.ui
# Error: 'PySide2.QtUiTools.QUiLoader.load' called with wrong argument
types:
# PySide2.QtUiTools.QUiLoader.load(type)
# Supported signatures:
# PySide2.QtUiTools.QUiLoader.load(PySide2.QtCore.QIODevice,
PySide2.QtWidgets.QWidget = None)
# PySide2.QtUiTools.QUiLoader.load(unicode, PySide2.QtWidgets.QWidget =
None)
# Traceback (most recent call last):
# File "<maya console>", line 1, in <module>
# File "E:\ProfessionalDevelopment\python\Introduction to Python
Scripting in Maya\cgcircuitPython\wk6\geomGenerator.py", line 18, in run
# win = GeometryGenerator(parent=getMayaWindow())
# File "E:\ProfessionalDevelopment\python\Introduction to Python
Scripting in Maya\cgcircuitPython\wk6\geomGenerator.py", line 32, in
__init__
# xfile.open(QtCore.QFile.ReadOnly)
# TypeError: 'PySide2.QtUiTools.QUiLoader.load' called with wrong argument
types:
# PySide2.QtUiTools.QUiLoader.load(type)
# Supported signatures:
# PySide2.QtUiTools.QUiLoader.load(PySide2.QtCore.QIODevice,
PySide2.QtWidgets.QWidget = None)
# PySide2.QtUiTools.QUiLoader.load(unicode, PySide2.QtWidgets.QWidget =
None) #
--
You received this message because you are subscribed to the Google Groups "Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_maya+***@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/58be15ea-88ec-4352-867a-14e82a4013a5%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Marcus Ottosson
2017-10-17 20:04:04 UTC
Permalink
I have another error.

What have you tried? Why do you think it happened? Does the error message
tell you anything? Have you searched online for an answer?
--
You received this message because you are subscribed to the Google Groups "Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_maya+***@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/CAFRtmOD7hV%3D-y98w0cxEYrkBQ6YO1W0bxx1FZqRUHhGKOwKGrw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.
Continue reading on narkive:
Loading...