global name 'cmds' is not defined - closures?

464 views
Skip to first unread message

Jakob Kousholt

unread,
Jan 1, 2019, 1:23:34 PM1/1/19
to Python Programming for Autodesk Maya
Hi Folks,

I'm currently working on a modelChecker to sanity check my 3d models. If I run the entire code from my script editor, everything can execute fine, but if I run the code using this:

import modelChecker
win = modelChecker.modelChecker(parent=modelChecker.getMainWindow())
win.show()

I get an error (Note the UI shows just fine. The error comes when you click the button "Run all checked"):

# Traceback (most recent call last):
#   File "/Users/jake/Library/Preferences/Autodesk/maya/2018/scripts/modelChecker.py", line 318, in sanityCheck
#     def sanityCheck(self):
#   File "/Users/jake/Library/Preferences/Autodesk/maya/2018/scripts/modelChecker.py", line 270, in filterNodes
#     allUsuableNodes = []
# NameError: global name 'cmds' is not defined

I am not exactly sure why "global name cmds" is not defined as I import it at the top of my script. Anyone know what is going on and what I should look for to fix it? I suspect it is something to do with scope and closures, but it seem to be going over my head. 

Sorry for the amount of code. It can be found on my github:

https://github.com/JakobJK/modelChecker/blob/master/modelChecker.py

Here's a screenshot of what the working modelChecker looks like from running the entire thing in the script editor vs importing the script.

Thanks in advance,

Jake

modelch.png


Justin Israel

unread,
Jan 1, 2019, 3:34:36 PM1/1/19
to python_in...@googlegroups.com
I don't have access to maya 2018 at the moment, so I tested your script on Maya 2016, after changing the imports to PySide 1.x. There was a syntax error at the bottom of your scripts that had to be fixed for it to be imported (if __name__ == '__main__'). But after I launched the UI, I found that running the button did not produce the error. The UI did produce a few other errors after repeat use, with assumptions about appending to lists that ended up being none, and some others. I'm not sure if this problem is limited to 2018 or something local to your workstation. 

Justin


--
You received this message because you are subscribed to the Google Groups "Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_m...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/be994670-d17e-4695-9735-124bf22ffc2c%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Jakob Kousholt

unread,
Jan 1, 2019, 9:55:26 PM1/1/19
to python_inside_maya
Hey Justin,
Thanks for taking a look. I still seem to be getting the error both on my mac and windows machine.
 The entire thing is very much WIP, so ton of bugs to iron out and many features to implement still. Thanks for pointing out the issue with the lists.


Jakob Kousholt - Freelance Creature Modeler and Concept Sculptor
jak...@gmail.com
www.jakejk.com


Justin Israel

unread,
Jan 2, 2019, 1:18:12 AM1/2/19
to python_in...@googlegroups.com


On Wed, Jan 2, 2019, 3:55 PM Jakob Kousholt <jak...@gmail.com> wrote:
Hey Justin,
Thanks for taking a look. I still seem to be getting the error both on my mac and windows machine.

I can let you know tomorrow after I try it out on Maya 2018. However my workstations are Linux. I don't feel it should make a difference though, seeing as you are reproducing the problem on two different platforms already. 

Nicolas Combecave

unread,
Jan 2, 2019, 12:38:54 PM1/2/19
to python_in...@googlegroups.com
I just gave it a try here, maya 2018, and all seems fine.


Jakob Kousholt

unread,
Jan 2, 2019, 3:31:27 PM1/2/19
to python_inside_maya
Thanks, Nicolas. Hmm... I'm quite confused. Can you tell me exactly how you ran it? I must be doing something wrong.

Jakob Kousholt - Freelance Creature Modeler and Concept Sculptor
jak...@gmail.com
www.jakejk.com

Marcus Ottosson

unread,
Jan 2, 2019, 3:37:35 PM1/2/19
to python_in...@googlegroups.com
I also ran it without trouble, and could "Run all checked" button too. Windows 10, Maya 2018.

I copied your code into a new file with the same name, and then ran the snippet you posted to show the window.

Justin Israel

unread,
Jan 2, 2019, 3:39:38 PM1/2/19
to python_in...@googlegroups.com
I've also just confirmed it to be working fine in linux, Maya 2018, using the same snippet.

Justin


Marcus Ottosson

unread,
Jan 2, 2019, 3:41:38 PM1/2/19
to python_in...@googlegroups.com

To replicate a “clean” environment, try this.

$ export MAYA_APP_DIR=~/mayatemp
$ export PYTHONPATH=
$ /path/to/maya

It will make a new maya preferences directory at that location, and not use any custom Python paths (if any). Should be getting a clean environment, and get the same result as what we’re getting.

Jakob Kousholt

unread,
Jan 3, 2019, 12:19:31 PM1/3/19
to python_inside_maya
Thank you all for letting me know. I can't tell if this is good or bad news. Haha! Something must be up with my local versions of maya.

Jakob Kousholt - Freelance Creature Modeler and Concept Sculptor
jak...@gmail.com
www.jakejk.com

Reply all
Reply to author
Forward
0 new messages