Hi.
As an original MEL scripter I have some issues understanding the ways of python in Maya.
Maybe I am expecting it to behave too much like MEL (I know it will never behave like mel. That is the beauty of Python, but I have some issues I am trying to wrap my brain around)
Let me explain the scenario.
I am building a UI which will work as a Main UI. A UI that I want to hook other layouts to. The way I used to do this with mel is like this
- build main Window. let’s call this “A_ui.mel”
- in a separate script create a UI, typically columnLayout and parent that into the main GUI if it exists. if not, source it and then hook it up. let’s call this script “B_ui.mel”
- in my main window script file, A_ui.mel I have a button which checks if the columnLayout exists, if not, source B_ui.mel and then it will hook itself up.
I am used to being able to source a script
source "path/path/script.mel"
and when I do that the whole script is sourced, the hole thing is passed to Memory so I can access anything I like there.
Now with python, if I import B_ui.py it does not seem to behave in that way.
The code below shows what I am trying to do (I don’t have kill UI etc here. It is more to show what I am thinking)
A_ui.py:
import maya.cmds as cmds
import B_ui
def buildUI():
cmds.window()
cmds.columnLayout('masterLayout')
cmds.button(c='B_ui.buildUI()')
B_ui.py:
import maya.cmds as cmds
def B_ui.buildUI():
cmds.columnLayout('b_uiColumn' , p='masterLayout')
cmds.button(c='b_function.createCube()')
and the b_function.py would look like this
import maya.cmds as cmds
def createCube():
print 'creating cube for you, sir!'
cmds.polyCube()
Now…
If I want to create a shelf button for this and I add
import a_ui
A_ui.buildUI
it builds the UI, but it seems like it ignores “import B_ui” at the start of the script.
The ui is built, but when I click the button to add the B_ui.buildUI() it does not execute.
If this was MEL I would know that if I source a script it would run through the entire thing so I would know that it would run through
all imports at the start of the script, but since I do not know python that well I suspect I am overlooking something and maybe I am ignoring something important. Maybe I can’t think like this at all.
The thought is that I should be able to just add new scripts to the MAIN UI whenever the need for a new script arises. So if we have 3 scripts hooked up to the main UI I should be able to write a script in a separate file and just hook it up to that UI. This way I do not destroy any code in the main UI file. Except that I would add import whateverNewScript at the start.
Can someone give me any pointers as to how you would attack this in python. If what I am trying to execute is unclear I can write some proper testScripts so we could break it down properly till it works. I am just trying to understand if I can even do what I am trying to do in python like this 
thanks,
M