Re: [Maya-Python] need help with userSetup.py

55 views
Skip to first unread message

Mahmoodreza Aarabi

unread,
Feb 16, 2016, 12:24:31 AM2/16/16
to python_in...@googlegroups.com

Hey man i suggest that use this method for running your window in maya:

class YourClass():
    ....

def getMainWindow():
    mainWindow = QtGui.QApplication.activeWindow()
    while True:
        lastWin = mainWindow.parent()
        if lastWin:
            mainWindow = lastWin
        else:
            break
    return mainWindow

def show():
        win = YourClass(parent=getMainWindow())
        win.show()

about your menu, just i can say put path of userSetup.py in your PYTHONPATH


On Mon, Feb 15, 2016 at 11:11 PM, md <acco...@mdonovan.com> wrote:
Hey Guys,

I am building my own Maya menu through userSetup.py ... 

I have written another python script which is basically just a pySide class. I want to call this script from the menu created in userSetup.py.

There is no main function .. just the class that gets instantiated at the bottom of the script with the following code. The script runs fine when run from the script editor.

Any insight would be awesome.

if __name__ == "__main__":
    
    try:
        cam_ui.deleteLater()
    except:
        pass
    
    cam_ui = smRealCameras()
    
    try:
        cam_ui.create()
        cam_ui.show()
    except:
        cam_ui.deleteLater()
        traceback.print_exc()        

I get this error in the command window when Maya launches ...

Failed to execute userSetup.py
Traceback (most recent call last):
  File "K:\ifs\resources\3D_resources\workgroups\maya_workgroup\net_modules\sm_module\scripts\userSetup.py", line 11, in <module>
    from create_cam_class import smRealCameras
  File "K:\ifs\resources\3D_resources\workgroups\maya_workgroup\net_modules\sm_module\scripts\create_cam_class.py", line 36, in <module>
    class smRealCameras (QtGui.QDialog) :
  File "K:\ifs\resources\3D_resources\workgroups\maya_workgroup\net_modules\sm_module\scripts\create_cam_class.py", line 37, in smRealCameras
    def __init__(self, parent=maya_main_window()):
  File "K:\ifs\resources\3D_resources\workgroups\maya_workgroup\net_modules\sm_module\scripts\create_cam_class.py", line 33, in maya_main_window
    return wrapInstance(long(main_window_ptr), QtGui.QWidget)
TypeError: long() argument must be a string or a number, not 'NoneType'

... here is my userSetup.py that builds the menu

import traceback

import maya.cmds as cmds
import maya.mel as mel
import maya.utils as utils
 
import sm_CreateProjectPlugin
from sm_CreateProjectPlugin_Maya_v0003 import *

import create_cam_class
from create_cam_class import smRealCameras

cmds.evalDeferred("build_menu()")

def build_menu():
if cmds.menu('sm_menu', exists=1):
cmds.deleteUI('sm_menu')
sm_menu = cmds.menu('sm_menu', parent='MayaWindow', tearOff=True, allowOptionBoxes=True, label='[===smoke && mirrors===]')
cmds.menuItem( divider=True)
cmds.menuItem(parent=sm_menu,  subMenu = True, label="Pipeline               ")
cmds.menuItem(l="create project", c = createProjectWindow)
cmds.menuItem(l ="real cams" c = smRealCameras)
cmds.menuItem(parent=sm_menu, divider=True)
cmds.menuItem(parent=sm_menu, subMenu = True, label="Rendering", enable=True)
cmds.menuItem(label="setup passes")
cmds.menuItem(label="render manager") 
cmds.menuItem(parent=sm_menu, label="Modeling",enable=False)
cmds.menuItem(parent=sm_menu, label="Lighting",enable=False)
cmds.menuItem(parent=sm_menu, divider=True)

Mike


--
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_m...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/ae3a6541-6982-4583-81fa-2d946e2c5029%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--


Bests,
madoodia
Reply all
Reply to author
Forward
0 new messages