I have a script that creates a window with UI.  It seems like any button actions that try to reference any global functions or other classes defined in the script get erased.

I get errors like NoneType is not callable.

My guess is the functions or classes get destroyed some how.

The really weird thing is I can't even create static methods in the class that is kept around that drives the UI.  I can call nonstatic methods on all of the existing objects that are kept around though.

Is there any solution at all or do I have to just not use any static methods?  I can see this making certain things impossible, like creating new instances of a class during some kind of UI action. 

  • created

    Nov '15
  • last reply

    Nov '15
  • 1

    reply

  • 1.5k

    views

  • 1

    user

  • 1

    link

12 days later

OK Figured it out.

You basically need to create a module and import the module, that way it stays permanently in the python environment without being forgotten as soon as the script runs and sets up the UI.  It's fine if you don't have UI and are just running a one off script.

This got me to reading up on modules in python, and took me to the next level of creating a full on complex project that I work on through Eclipse and Pydev. http://www.creativecrash.com/tutorials/using-eclipse-as-a-maya-ide/page3#tabs4

Lots of other plugins work this way as well.  This explains why when adding a python plugin to your shelf, the code that goes into the button is typically:

import mainPluginModuleGoesHere
mainPluginModuleGoesHere.main()

and main is the entry point that sets up all the UI, but it can be called anything besides main, like run, go, etc...