Right now Im working on a somewhat larger PyMEL project than I’ve done in the past. My idea is to make it modular, having a core module/script file that the user needs - and then several opional scripts that the user can chose or not chose to use. Every file has a class definition in it, and under that I’ve added the class methods/functions. Before you ask me why Im using classes everywhere: I’m not sure when it’s a good idea to use a class object or not. I know that code and functions can be written directly in the root of the script document!
So the structure is like this:
import random
import pymel.core as pm
import maya.mel as mm
class my_tool():
# Class variables
# UI names
## Initialize
def __init__(self):
# Draw UI
self.createUI()
# Some other stuff, like running self.loadOptVars() - a method that creates/loads option variables
########## Methods ##########
def some_method(self):
pass
# More methods
########## UI-related ##########
def createUI(self):
pass
[B][/B]
My issue is that I can’t seem to properly import these other modules (import to my core module, or import the core module from another script if it’s being run stand-alone).
I’ve tried both from module import * as well as from module import function and import module as md - but no matter how I write the import, the methods doesn’t seem to import properly because Maya says they cant be run. My guess is that it’s a namespace issue.
The particular method I want to run from moduleX is defined as a static method with the @staticmethod descriptor right before the definition - so they are not tied to working only with a class instance. So yea, obviously I’ve not layed these script files out as they should - or the namespace is wrong or Im missing something else. All help is appreciated.
(also, class name is the same as the script name - is that an issue?)