<?xml version="1.0" encoding="UTF-8" ?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>Detect if I am running from maya?</title>
    <link>https://www.tech-artists.org/t/detect-if-i-am-running-from-maya/3734</link>
    <description>Is there preferred method, or method at all, for detecting if I am running (python) from Maya?

Basically, I am working on a template for a generic PyQT window class, that will:
1. run and load in vanilla python (2.6) create a QApplication, load a .ui file, make a toolWindow object attached to the app
*I know how to setup and load a generic PyQT object, etc. 

or

2. If I am running from Maya, will get the mainWindow, and create my toolWindow and parent it to mainWindow
*I know how to do all this PyQT setup and stuff working with maya

I know what code I basically need to portion off into say a maya based class method, stuff like:

#Create/Reload window instance in maya
if cmds.window(self.mainWindowName, exists=True ):
[INDENT]cmds.deleteUI(self.mainWindowName, window=True )[/INDENT]      
pass

I also need to control weather or not I am doing maya imports i.e. &#39;import maya.cmds as cmds&#39;.

I just can&#39;t find a great solution, my fallback is maybe something like:
global gMaya
gMaya = False

... and then carry that scope through the classes, but override with =True in some sort of wrapper that maya calls.

Anyone have thoughts?</description>
    
    <lastBuildDate>Wed, 03 Apr 2019 22:40:40 +0000</lastBuildDate>
    <category>Coding</category>
    <atom:link href="https://www.tech-artists.org/t/detect-if-i-am-running-from-maya/3734.rss" rel="self" type="application/rss+xml" />
      <item>
        <title>Detect if I am running from maya?</title>
        <dc:creator><![CDATA[Theodox]]></dc:creator>
        <description><![CDATA[
            <p>I don’ think you need to bother with the global vars and so on.  With a folder setup like:</p>
<pre><code> /myModule
     __init__.py
    common.py
    mayaOnly.py
    nonMaya.py
</code></pre>
<p>You just do the initialization in <code>__init__.py</code> at import time:</p>
<pre><code class="lang-auto">
import os, sys

if os.path.basename(sys.executable) == 'mayapy.exe':
   import mayaOnly as host
else:
   import  nonMaya as host

</code></pre>
<p>and in both mayaOnly.py and nonMaya you’d start with</p>
<pre><code class="lang-auto">
from common import *

</code></pre>
<p>All code outside the module would just do</p>
<pre><code class="lang-auto">
from myMod import host
host.createWindow()  # which does any host specific setup
something = host.im_a_common_function()  #this is the same func no mattter what environment

</code></pre>
<p>The hassle factor is primarily that public functions in mayaOnly.py and nonMaya.py need to have the same signatures.  That’s a great use for automatic testing <img src="//discourse.techart.online/images/emoji/twitter/slight_smile.png?v=6" title=":slight_smile:" class="emoji" alt=":slight_smile:"></p>
          <p><a href="https://www.tech-artists.org/t/detect-if-i-am-running-from-maya/3734/14">Read full topic</a></p>
        ]]></description>
        <link>https://www.tech-artists.org/t/detect-if-i-am-running-from-maya/3734/14</link>
        <pubDate>Thu, 27 Jun 2013 11:48:19 +0000</pubDate>
        <guid isPermaLink="false">www.tech-artists.org-post-3734-14</guid>
        <source url="https://www.tech-artists.org/t/detect-if-i-am-running-from-maya/3734.rss">Detect if I am running from maya?</source>
      </item>
      <item>
        <title>Detect if I am running from maya?</title>
        <dc:creator><![CDATA[capper]]></dc:creator>
        <description><![CDATA[
            <p>[QUOTE=madyasiwi;21700]This is basically how we do it:</p>
<pre><code class="lang-auto">import sys, os, re

if re.match( "maya\\.exe", os.path.basename( sys.executable ), re.I ):
    print "Running in Maya."
</code></pre>
<p>[/QUOTE]</p>
<p>I like this method. Thanks madyasiwi.</p>
          <p><a href="https://www.tech-artists.org/t/detect-if-i-am-running-from-maya/3734/13">Read full topic</a></p>
        ]]></description>
        <link>https://www.tech-artists.org/t/detect-if-i-am-running-from-maya/3734/13</link>
        <pubDate>Thu, 27 Jun 2013 10:36:38 +0000</pubDate>
        <guid isPermaLink="false">www.tech-artists.org-post-3734-13</guid>
        <source url="https://www.tech-artists.org/t/detect-if-i-am-running-from-maya/3734.rss">Detect if I am running from maya?</source>
      </item>
      <item>
        <title>Detect if I am running from maya?</title>
        <dc:creator><![CDATA[hogjonny]]></dc:creator>
        <description><![CDATA[
            <p>[QUOTE=capper;21687]Wouldn’t something like this do the trick for a one-time check?</p>
<pre><code class="lang-auto">try:
    import maya.cmds as cmds
except ImportError:
    # no maya
else:
    # If for some reason you had the maya module in your sys.path
    try:
        if cmds.about(batch=True):
            # in batch mode
    except AttributeError:
        # cmds module isn't fully loaded/populated (which only happens in batch, maya.standalone, or maya GUI)
        # no maya
</code></pre>
<p>[/QUOTE]</p>
<p>This method works well.<br>
I have played around with using this code at the top of a module to control imports - something structured based on your suggestion:</p>
<pre><code class="lang-auto">
# -------------------------------------------------------------------------
global gMaya
gMaya = None

# -------------------------------------------------------------------------
# run this, if we are in Maya
def setMaya(gMaya):
    gMaya = True
    # Other Maya setup
    #
    return gMaya

# -------------------------------------------------------------------------
# run this if we are NOT in Maya
def setNoMaya(gMaya):
    gMaya = False
    # other setup stuff
    #
    return gMaya   

# -------------------------------------------------------------------------
try:
    import maya.cmds as cmds
    setMaya(gMaya)
except ImportError:
    # NO Maya
    setNoMaya(gMaya)
else:
    # If for some reason you had the maya module in your sys.path
    try:
        if cmds.about(batch=True):
            # in batch mode
            setMaya(gMaya)
    except AttributeError:
        # cmds module isn't fully loaded/populated (which only happens in batch,
        # maya.standalone, or maya GUI)
        # NO Maya
        setNoMaya(gMaya)

# -------------------------------------------------------------------------
# Now, run the import IF we are running from Maya
if gMaya:
    import maya.OpenMayaUI as omui

</code></pre>
<p>I also setup a similar test using a derivative of this method for switching/controlling imports at the UI packages level…  &amp;lt;package_ui&gt;_<em>init</em>_.py</p>
<p>So as suggested, I can have one set of modules for non-Maya, and another set of counterparts for Maya.  I like this later method the best, thanks again.</p>
          <p><a href="https://www.tech-artists.org/t/detect-if-i-am-running-from-maya/3734/12">Read full topic</a></p>
        ]]></description>
        <link>https://www.tech-artists.org/t/detect-if-i-am-running-from-maya/3734/12</link>
        <pubDate>Thu, 27 Jun 2013 07:44:01 +0000</pubDate>
        <guid isPermaLink="false">www.tech-artists.org-post-3734-12</guid>
        <source url="https://www.tech-artists.org/t/detect-if-i-am-running-from-maya/3734.rss">Detect if I am running from maya?</source>
      </item>
      <item>
        <title>Detect if I am running from maya?</title>
        <dc:creator><![CDATA[madyasiwi]]></dc:creator>
        <description><![CDATA[
            <p>This is basically how we do it:</p>
<pre><code class="lang-auto">import sys, os, re

if re.match( "maya\\.exe", os.path.basename( sys.executable ), re.I ):
    print "Running in Maya."
</code></pre>
          <p><a href="https://www.tech-artists.org/t/detect-if-i-am-running-from-maya/3734/11">Read full topic</a></p>
        ]]></description>
        <link>https://www.tech-artists.org/t/detect-if-i-am-running-from-maya/3734/11</link>
        <pubDate>Thu, 27 Jun 2013 07:37:16 +0000</pubDate>
        <guid isPermaLink="false">www.tech-artists.org-post-3734-11</guid>
        <source url="https://www.tech-artists.org/t/detect-if-i-am-running-from-maya/3734.rss">Detect if I am running from maya?</source>
      </item>
      <item>
        <title>Detect if I am running from maya?</title>
        <dc:creator><![CDATA[hogjonny]]></dc:creator>
        <description><![CDATA[
            <p>[QUOTE=Theodox;21691]well, part of it is I’d just let the command fail on bad inputs  - that’s how you find the bugs :).   flat If-tests , like “if not node: return”  are fine too: they let you bail out as needed and don’t complicate program flow.  What’s bad is multiple tests of the same value, or deeply nested tests, or worst of all both at once – it can quickly become impossible to be sure what code is running.  If you’ve never read it, The Art Of Readable Code has a great discussion of if-ing</p>
<p>However the pythonic alternative for multiple choice situations is to use dictionary lookups</p>
<pre><code class="lang-auto">

def foo (node):
    nt = cmds.nodeType(mesh)  # let it fail - if i call it empty, the bug needs to be identified

    def mesh_func(node):
       print "I'm a mesh"

    def dummy_func(node):
       print "i dont know what to do with %s" % node

    curve_func = lambda p: print p + "is a curve"
    
    opts = {'mesh': mesh_func, 'curve': curve_func}  
   # the callables are stuffed into the dictionary
    func_to_call = opts.get(nt , dummy)  
    # dummy func is the default value
    func_to_call(nt )

</code></pre>
<p>this looks more complex (for a short example like this it is!) but it has two big plusses:</p>
<ol>
<li>
<p>you can expand it easily:  the sub-defs or lambdas are clearly self contained. If the same functionality were wrapped in ifs you’d have to watch your indents and exit points all the way down.  Adding a new function doesn’t disturb existing code at all. And of course they can just be other functions - I only inlined them here to make the point.</p>
</li>
<li>
<p>in practice, you would probably not want the sub defs in line. They could be class member functions (that’s the most common) but you could also do by configuring at runtime:</p>
</li>
</ol>
<pre><code class="lang-auto">

def mesh_func (mesh):
    #blah

def curve func(curve)(:
    #blah

def light_func(light): 
    # blah

def fail(node):
   print "unrecognized node"

def foo (node, **opts)
    nt = cmds.nodeType(node) 
    opts.get(nt, fail)(nt)

def handle_lights_and_curves(node):
    foo (node, curve=curve_func, light=light_func)

def handle_curves_and_meshes(node):
    foo (node, curve=curve_func, mesh=mesh_func)


</code></pre>
<p>[/QUOTE]</p>
<blockquote>
<p>…it can quickly become impossible to be sure what code is running…</p>
</blockquote>
<p>On that note, when I do have some trouble tracking code flow in loops or branches, even with a IDE and the stack, I fall back to logging.<br>
I recently added this method to my simple logging class I setup, It’ll return nice information about where it was called from - it will log the current function, the file it is in and line number the function starts.</p>
<pre><code class="lang-auto">
    #----------------------------------------------------------------------    
    def autolog(self, message):
        '''Automatically log the current function details.'''
        # Get the previous frame in the stack, otherwise it would
        # be this function!!!
        func = inspect.currentframe().f_back.f_code
        # Dump the message + the name of this function to the log.
        self.log.debug( '{0}: {1} in {2}:{3}'
                        ''.format( message,
                                   func.co_name,
                                   func.co_filename, 
                                   func.co_firstlineno)
                        ) #end

</code></pre>
<p>I use it like this:</p>
<p>&gt;&gt; LOG = SetupLogger():<br>
&gt;&gt; logMessage = ‘Testing’<br>
&gt;&gt; LOG.autolog(logMessage)</p>
<p>and it’ll return something like this&gt;&gt; 2013-06-21 09:33:01,193 - DEBUG - Testing: main in C:\depot\bpTools\maya\python\packages\bp_debugLogger\bp_debugLogger.py:281</p>
          <p><a href="https://www.tech-artists.org/t/detect-if-i-am-running-from-maya/3734/10">Read full topic</a></p>
        ]]></description>
        <link>https://www.tech-artists.org/t/detect-if-i-am-running-from-maya/3734/10</link>
        <pubDate>Thu, 27 Jun 2013 07:30:27 +0000</pubDate>
        <guid isPermaLink="false">www.tech-artists.org-post-3734-10</guid>
        <source url="https://www.tech-artists.org/t/detect-if-i-am-running-from-maya/3734.rss">Detect if I am running from maya?</source>
      </item>
      <item>
        <title>Detect if I am running from maya?</title>
        <dc:creator><![CDATA[Theodox]]></dc:creator>
        <description><![CDATA[
            <p>And btw: Maya.standalone.initialize() is SLOOOW if it does run <img src="//discourse.techart.online/images/emoji/twitter/slight_smile.png?v=5" title=":slight_smile:" class="emoji" alt=":slight_smile:"></p>
          <p><a href="https://www.tech-artists.org/t/detect-if-i-am-running-from-maya/3734/9">Read full topic</a></p>
        ]]></description>
        <link>https://www.tech-artists.org/t/detect-if-i-am-running-from-maya/3734/9</link>
        <pubDate>Wed, 26 Jun 2013 17:02:29 +0000</pubDate>
        <guid isPermaLink="false">www.tech-artists.org-post-3734-9</guid>
        <source url="https://www.tech-artists.org/t/detect-if-i-am-running-from-maya/3734.rss">Detect if I am running from maya?</source>
      </item>
      <item>
        <title>Detect if I am running from maya?</title>
        <dc:creator><![CDATA[Theodox]]></dc:creator>
        <description><![CDATA[
            <p>well, part of it is I’d just let the command fail on bad inputs  - that’s how you find the bugs :).   flat If-tests , like “if not node: return”  are fine too: they let you bail out as needed and don’t complicate program flow.  What’s bad is multiple tests of the same value, or deeply nested tests, or worst of all both at once – it can quickly become impossible to be sure what code is running.  If you’ve never read it, The Art Of Readable Code has a great discussion of if-ing</p>
<p>However the pythonic alternative for multiple choice situations is to use dictionary lookups</p>
<pre><code class="lang-auto">

def foo (node):
    nt = cmds.nodeType(mesh)  # let it fail - if i call it empty, the bug needs to be identified

    def mesh_func(node):
       print "I'm a mesh"

    def dummy_func(node):
       print "i dont know what to do with %s" % node

    curve_func = lambda p: print p + "is a curve"
    
    opts = {'mesh': mesh_func, 'curve': curve_func}  
   # the callables are stuffed into the dictionary
    func_to_call = opts.get(nt , dummy)  
    # dummy func is the default value
    func_to_call(nt )

</code></pre>
<p>this looks more complex (for a short example like this it is!) but it has two big plusses:</p>
<ol>
<li>
<p>you can expand it easily:  the sub-defs or lambdas are clearly self contained. If the same functionality were wrapped in ifs you’d have to watch your indents and exit points all the way down.  Adding a new function doesn’t disturb existing code at all. And of course they can just be other functions - I only inlined them here to make the point.</p>
</li>
<li>
<p>in practice, you would probably not want the sub defs in line. They could be class member functions (that’s the most common) but you could also do by configuring at runtime:</p>
</li>
</ol>
<pre><code class="lang-auto">

def mesh_func (mesh):
    #blah

def curve func(curve)(:
    #blah

def light_func(light): 
    # blah

def fail(node):
   print "unrecognized node"

def foo (node, **opts)
    nt = cmds.nodeType(node) 
    opts.get(nt, fail)(nt)

def handle_lights_and_curves(node):
    foo (node, curve=curve_func, light=light_func)

def handle_curves_and_meshes(node):
    foo (node, curve=curve_func, mesh=mesh_func)


</code></pre>
          <p><a href="https://www.tech-artists.org/t/detect-if-i-am-running-from-maya/3734/8">Read full topic</a></p>
        ]]></description>
        <link>https://www.tech-artists.org/t/detect-if-i-am-running-from-maya/3734/8</link>
        <pubDate>Wed, 26 Jun 2013 16:58:39 +0000</pubDate>
        <guid isPermaLink="false">www.tech-artists.org-post-3734-8</guid>
        <source url="https://www.tech-artists.org/t/detect-if-i-am-running-from-maya/3734.rss">Detect if I am running from maya?</source>
      </item>
      <item>
        <title>Detect if I am running from maya?</title>
        <dc:creator><![CDATA[rgkovach123]]></dc:creator>
        <description><![CDATA[
            <p>[QUOTE=Theodox;21685]I’d strongly recommend against if testing all over your code!!  …  ‘If’ statements are always evil.[/QUOTE]</p>
<p>how would you recommend handling a case like this?</p>
<pre><code class="lang-auto">
def foo(node=None):
    if not isinstance(node, basestring):
        print 'not a string!'
        return
    if not node:
        print 'nothing to work on!'
        return
    if cmds.nodeType(node) != 'mesh':
        print 'expected a shape node!'
        return
    # node is a valid input, do something to it.

</code></pre>
          <p><a href="https://www.tech-artists.org/t/detect-if-i-am-running-from-maya/3734/7">Read full topic</a></p>
        ]]></description>
        <link>https://www.tech-artists.org/t/detect-if-i-am-running-from-maya/3734/7</link>
        <pubDate>Wed, 26 Jun 2013 14:45:17 +0000</pubDate>
        <guid isPermaLink="false">www.tech-artists.org-post-3734-7</guid>
        <source url="https://www.tech-artists.org/t/detect-if-i-am-running-from-maya/3734.rss">Detect if I am running from maya?</source>
      </item>
      <item>
        <title>Detect if I am running from maya?</title>
        <dc:creator><![CDATA[hogjonny]]></dc:creator>
        <description><![CDATA[
            <p>[QUOTE=capper;21687]Wouldn’t something like this do the trick for a one-time check?</p>
<pre><code class="lang-auto">try:
    import maya.cmds as cmds
except ImportError:
    # no maya
else:
    # If for some reason you had the maya module in your sys.path
    try:
        if cmds.about(batch=True):
            # in batch mode
    except AttributeError:
        # cmds module isn't fully loaded/populated (which only happens in batch, maya.standalone, or maya GUI)
        # no maya
</code></pre>
<p>Or even using imp.find_module? I can’t think of an instance where you’d be able to import maya.cmds and not be in a maya session (even with mayapy[/QUOTE]</p>
<p>Thank you, I’ll experiment with these methods also!</p>
<p>BTW - I was looking at tests like ‘sys.version’ but it returns the python version, which isn’t useful in detecting maya.<br>
Then I was on the hunt again, and I stumbled across this in the documentation:</p>
<pre><code class="lang-auto">
TipTo find whether you are in Maya's internal Python interpreter, you can execute the following code block:


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


If you are in Maya's internal Python interpreter, the initialize() call will throw an exception, which will be safely caught.
</code></pre>
<p><a href="http://download.autodesk.com/us/maya/2010help/index.html?url=Python_Python_from_an_external_interpreter.htm,topicNumber=d0e182872" rel="noopener nofollow ugc">LINK</a></p>
          <p><a href="https://www.tech-artists.org/t/detect-if-i-am-running-from-maya/3734/6">Read full topic</a></p>
        ]]></description>
        <link>https://www.tech-artists.org/t/detect-if-i-am-running-from-maya/3734/6</link>
        <pubDate>Wed, 26 Jun 2013 13:54:48 +0000</pubDate>
        <guid isPermaLink="false">www.tech-artists.org-post-3734-6</guid>
        <source url="https://www.tech-artists.org/t/detect-if-i-am-running-from-maya/3734.rss">Detect if I am running from maya?</source>
      </item>
      <item>
        <title>Detect if I am running from maya?</title>
        <dc:creator><![CDATA[hogjonny]]></dc:creator>
        <description><![CDATA[
            <p>[QUOTE=Theodox;21685]cheap way to find out if you’re in maya:</p>
<pre><code class="lang-auto">
import sys

def is_interactive_maya():
    return type (sys.stdout) != file

</code></pre>
<p>I’d strongly recommend against if testing all over your code!!  Break it up into maya-specific, non-maya-specific, and common sections.  If the Maya and non-Maya versions have identical signatures you can swap them in at load time and the rest of the code doesn’t care.  ‘If’ statements are always evil.[/QUOTE]</p>
<p>That’s a good idea too, I’ll try it out.  I was thinking I would just have a maya-only setup Class.method(), which would only get called in the <strong>init</strong> if I detected that I was running in maya.</p>
          <p><a href="https://www.tech-artists.org/t/detect-if-i-am-running-from-maya/3734/5">Read full topic</a></p>
        ]]></description>
        <link>https://www.tech-artists.org/t/detect-if-i-am-running-from-maya/3734/5</link>
        <pubDate>Wed, 26 Jun 2013 13:46:24 +0000</pubDate>
        <guid isPermaLink="false">www.tech-artists.org-post-3734-5</guid>
        <source url="https://www.tech-artists.org/t/detect-if-i-am-running-from-maya/3734.rss">Detect if I am running from maya?</source>
      </item>
      <item>
        <title>Detect if I am running from maya?</title>
        <dc:creator><![CDATA[capper]]></dc:creator>
        <description><![CDATA[
            <p>Wouldn’t something like this do the trick for a one-time check?</p>
<pre><code class="lang-auto">try:
    import maya.cmds as cmds
except ImportError:
    # no maya
else:
    # If for some reason you had the maya module in your sys.path
    try:
        if cmds.about(batch=True):
            # in batch mode
    except AttributeError:
        # cmds module isn't fully loaded/populated (which only happens in batch, maya.standalone, or maya GUI)
        # no maya
</code></pre>
          <p><a href="https://www.tech-artists.org/t/detect-if-i-am-running-from-maya/3734/4">Read full topic</a></p>
        ]]></description>
        <link>https://www.tech-artists.org/t/detect-if-i-am-running-from-maya/3734/4</link>
        <pubDate>Wed, 26 Jun 2013 13:40:55 +0000</pubDate>
        <guid isPermaLink="false">www.tech-artists.org-post-3734-4</guid>
        <source url="https://www.tech-artists.org/t/detect-if-i-am-running-from-maya/3734.rss">Detect if I am running from maya?</source>
      </item>
      <item>
        <title>Detect if I am running from maya?</title>
        <dc:creator><![CDATA[Theodox]]></dc:creator>
        <description><![CDATA[
            <p>BTW that test can be confused if you’ve taken over sys.stdout yourself <img src="//discourse.techart.online/images/emoji/twitter/slight_smile.png?v=5" title=":slight_smile:" class="emoji" alt=":slight_smile:">  You can also look to see of the word “Autodesk” shows up in sys.path…</p>
          <p><a href="https://www.tech-artists.org/t/detect-if-i-am-running-from-maya/3734/3">Read full topic</a></p>
        ]]></description>
        <link>https://www.tech-artists.org/t/detect-if-i-am-running-from-maya/3734/3</link>
        <pubDate>Wed, 26 Jun 2013 11:37:06 +0000</pubDate>
        <guid isPermaLink="false">www.tech-artists.org-post-3734-3</guid>
        <source url="https://www.tech-artists.org/t/detect-if-i-am-running-from-maya/3734.rss">Detect if I am running from maya?</source>
      </item>
      <item>
        <title>Detect if I am running from maya?</title>
        <dc:creator><![CDATA[Theodox]]></dc:creator>
        <description><![CDATA[
            <p>cheap way to find out if you’re in maya:</p>
<pre><code class="lang-auto">
import sys

def is_interactive_maya():
    return type (sys.stdout) != file

</code></pre>
<p>I’d strongly recommend against if testing all over your code!!  Break it up into maya-specific, non-maya-specific, and common sections.  If the Maya and non-Maya versions have identical signatures you can swap them in at load time and the rest of the code doesn’t care.  ‘If’ statements are always evil.</p>
          <p><a href="https://www.tech-artists.org/t/detect-if-i-am-running-from-maya/3734/2">Read full topic</a></p>
        ]]></description>
        <link>https://www.tech-artists.org/t/detect-if-i-am-running-from-maya/3734/2</link>
        <pubDate>Wed, 26 Jun 2013 11:33:18 +0000</pubDate>
        <guid isPermaLink="false">www.tech-artists.org-post-3734-2</guid>
        <source url="https://www.tech-artists.org/t/detect-if-i-am-running-from-maya/3734.rss">Detect if I am running from maya?</source>
      </item>
      <item>
        <title>Detect if I am running from maya?</title>
        <dc:creator><![CDATA[hogjonny]]></dc:creator>
        <description><![CDATA[
            <p>Is there preferred method, or method at all, for detecting if I am running (python) from Maya?</p>
<p>Basically, I am working on a template for a generic PyQT window class, that will:</p>
<ol>
<li>run and load in vanilla python (2.6) create a QApplication, load a .ui file, make a toolWindow object attached to the app<br>
*I know how to setup and load a generic PyQT object, etc.</li>
</ol>
<p>or</p>
<ol start="2">
<li>If I am running from Maya, will get the mainWindow, and create my toolWindow and parent it to mainWindow<br>
*I know how to do all this PyQT setup and stuff working with maya</li>
</ol>
<p>I know what code I basically need to portion off into say a maya based class method, stuff like:</p>
<p><span class="hashtag">#Create</span>/Reload window instance in maya<br>
if cmds.window(self.mainWindowName, exists=True ):<br>
[INDENT]cmds.deleteUI(self.mainWindowName, window=True )[/INDENT]<br>
pass</p>
<p>I also need to control weather or not I am doing maya imports i.e. ‘import maya.cmds as cmds’.</p>
<p>I just can’t find a great solution, my fallback is maybe something like:<br>
global gMaya<br>
gMaya = False</p>
<p>… and then carry that scope through the classes, but override with =True in some sort of wrapper that maya calls.</p>
<p>Anyone have thoughts?</p>
          <p><a href="https://www.tech-artists.org/t/detect-if-i-am-running-from-maya/3734/1">Read full topic</a></p>
        ]]></description>
        <link>https://www.tech-artists.org/t/detect-if-i-am-running-from-maya/3734/1</link>
        <pubDate>Wed, 26 Jun 2013 10:34:09 +0000</pubDate>
        <guid isPermaLink="false">www.tech-artists.org-post-3734-1</guid>
        <source url="https://www.tech-artists.org/t/detect-if-i-am-running-from-maya/3734.rss">Detect if I am running from maya?</source>
      </item>
  </channel>
</rss>