Hello there.
I have problem with converting one of my mel scripts to Python and haven’t find solution, so I came here for help. Now let me tell you that I am newbie when it comes to Python, I have some experience with mel scripts and that’s it. I do however converted my simple scriptedRig.mel to Python successfully, but functions there were independant of each other, not like in this case…
So to simulate problem I created very simple testWindow.py file, then created a button on Maya shelf with command:
CODE
import testWindow
reload (testWindow)
testWindow.testWindow()
I know that I calling only the first function by doing it like that. But if I wrote testWindow() I get TypeError: 'module' object is not callable.
Script itself contains this code:
CODE
import maya.cmds as mc
def testWindow():
MyWin = mc.window( title=“Long Name”, iconName=‘Short Name’, widthHeight=(200, 55) )
mc.columnLayout( adjustableColumn=True )
mc.button( label=‘Do Nothing’ )
mc.button( label=‘Close’, command=(‘mc.deleteUI("’ + MyWin + ‘", window=True)’) )
mc.button( label=‘delUI’, command=deleteWindow())
mc.setParent( ‘..’ )
mc.showWindow( MyWin )
def deleteWindow():
mc.deleteUI( MyWin, window=True )
MyWin variable is contained in the first function, but the second function executes as a button by first.
If I write it like this:
CODE
import maya.cmds as mc
def testWindow():
MyWin = mc.window( title=“Long Name”, iconName=‘Short Name’, widthHeight=(200, 55) )
mc.columnLayout( adjustableColumn=True )
mc.button( label=‘Do Nothing’ )
mc.button( label=‘Close’, command=(‘mc.deleteUI("’ + MyWin + ‘", window=True)’) )
mc.button( label=‘delUI’, command=deleteWindow())
mc.setParent( ‘..’ )
mc.showWindow( MyWin )
def deleteWindow():
mc.deleteUI( MyWin, window=True )
it will give me: \# Error: local variable 'deleteWindow' referenced before assignment
Which is of course totally true, but how can I pass that? If I put deleteWindow() function first, then MyWin variable will not be defind and this is such an easy script. Does functions in Python have no chance to act like global procedures in mel? How to make them work with each other?
I downloaded two Kel Solaar's Python scripts to examine them on how this problem solved, but I failed to execute them!
I realize that this question may be stupid and answer may be right under my nose, but I really can't find answer on this topic.
p.s. Oh and I hope that you understand me, because my english is really bad...