How to check if running maya with mayapy

1,455 views
Skip to first unread message

Jonas Avrin

unread,
Aug 20, 2012, 9:31:47 PM8/20/12
to python_in...@googlegroups.com
Maya docs say:

try:
    import maya.standalone
    maya.standalone.initialize()
except:
    pass

This makes my mayapy crash when running this test in userSetup.py
Windows 7 64 bit Maya -ver 2012-x64

Anybody else have different techniques?

Chad Dombrova

unread,
Aug 20, 2012, 10:32:57 PM8/20/12
to python_in...@googlegroups.com
i'm not quite clear on what you want to do. do you want to know if userSetup.py is running in mayapy versus batch mode versus interactive? IIRC, calling maya.standalone.initialize() in mayapy is what triggers userSetup.py to get called, so just by virtue of it running you can know that maya is in the *process* of being initialized.

-chad




Message has been deleted

Jonas Avrin

unread,
Aug 20, 2012, 11:33:16 PM8/20/12
to python_in...@googlegroups.com
I would like to know a reliable way to test if userSetup.py is being run in mayapy interactive in order to bypass UI tools during startup.  I guess maya.cmds.about(batch=True) works. 

Chad Dombrova

unread,
Aug 21, 2012, 3:09:25 AM8/21/12
to python_in...@googlegroups.com
there is also maya.OpenMaya.MGlobal.mayaState() which provides even more granular info. it will return kInteractive in GUI, kLibraryApp in mayapy (after maya has been initialized), and kBatch in batch mode (i.e maya -prompt or maya -batch). you have to be careful about the second one though, because in mayapy it will return kInteractive before maya has been initialized.

-chad

Justin Israel

unread,
Aug 21, 2012, 11:46:13 AM8/21/12
to python_in...@googlegroups.com, python_in...@googlegroups.com
Another way, if I remember correctly without being at a computer, is to just see if the main window evals:

mainWin = maya.mel.eval("$temp1=$gMainWindow")

If mainWin is blank then you are not in a gui. You can also do it with the api, to get a main window ref. but I dont have the docs in front of me.




On Aug 21, 2012, at 12:09 AM, Chad Dombrova <cha...@gmail.com> wrote:

> there is also maya.OpenMaya.MGlobal.mayaState() which provides even more granular info. it will return kInteractive in GUI, kLibraryApp in mayapy (after maya has been initialized), and kBatch in batch mode (i.e maya -prompt or maya -batch). you have to be careful about the second one though, because in mayapy it will return kInteractive before maya has been initialized.
>
> -chad
>
> --
> view archives: http://groups.google.com/group/python_inside_maya
> change your subscription settings: http://groups.google.com/group/python_inside_maya/subscribe

Jonas Avrin

unread,
Aug 22, 2012, 10:42:11 PM8/22/12
to python_in...@googlegroups.com
Great, thanks guys!
Reply all
Reply to author
Forward
0 new messages