Chapter 7
Basic Tools with Maya Commands
Author
Adam Mechtley
Project
Tool GUI Template, Polygon Primitives tool, Pose Manager tool
Example Files
optwin.py
polywin.py
posemgr.py
posemgr1.ma
posemgr2.ma
Synopsis
This chapter introduces the basics of creating a Maya GUI window. Readers will use the cmds module to create a base window class with a menu and buttons that they can extend for their own tools. We introduce additional GUI commands available in the cmds module to extend this base class and implement radio buttons, input fields, and color pickers in a simple polygon creation tool. Finally, we cover some advanced techniques for tool development including code organization, data serialization with the pickle module, and working with files in a Maya GUI. The final code example is a basic tool that can copy, paste, save, and load poses on characters.
Resources
functools Documentation
pickle Documentation
Reading and Writing Files
Other Notes
None
Errata for the First Edition
In the optwin.py module (AR_OptionsWindow class), the call to tabLayout should have set the childResizable flag. The file available for download reflects this change.
Hello,
I am trying to complete the exercise on “Using functools Module” but I keep getting an error that reads:
#Error: keyword cannot be an expression
Any help here would be appreciated. I know its a small issue but it will bother me until I get it:)
Thanks for the wonderful book.
Michael
Michael Harants said this on September 9, 2012 at 3:33 am |
Hi Michael! Can you be a little more specific about precisely where you get the problem, what line, what your code looks like, etc.? I tried the example in the book again and get no problems.
Adam said this on September 15, 2012 at 10:25 am |
Hi, I actually posted a thread on CG talk with several issues I’m having in chapter 7.
Thought to post it here just aswell if there could be the slightest chance you’d answer 😉
http://forums.cgsociety.org/showthread.php?p=7642584#post7642584
Thanks, and the book is great! Took me a while to get started for real though.
Dag Isaksson said this on August 16, 2013 at 3:26 am |
Hi
I want to start of by congratulating the authors to a fantastic book! I have read it front to back and feel that I master a lot of python programming by now.
I am currently working on some simulations in Maya for which I need some graphical interfaces. By using your optwin class I was able to extend it to my own class and build a custom window, but now I have the problem that I want to open a second window when the first one is closed. And even though I put an identic call to a new window it only pops open for the fraction of a second before it is closed by it self. Any idea what is causing this?
I call the window using:
win = cellWin.AR_CellOptionsWindow.showUI(self)
and then one more time at another place in my script.
Further more, I want to start a loop when the window is closed where I basically iterate over the full timescale of the scen like
for t in range(tmax):
currentTime(t)
# do something
but even though this loop is called after the close button on the window is pressed, the loop starts before the window is closed and remains open until the end of the loop. Any clue why this is happening?
Very grateful for any advice
Best Regards
Emil Ljungberg
Lund University, Sweden
Emil Ljungberg said this on December 4, 2013 at 8:48 am |
Hi,
Can you explain a little more about why we need to use
mel.eval(`python(“import maya.cmds”);`)
at the bottom of page 203? I just don’t get it. Why couldn’t we just do
import maya.cmds
?
thanks!
john patterson said this on March 30, 2015 at 11:44 am |
Hi John! As mentioned in the text, passing a string command as a callback executes the statements in the __main__ module. If you want to make sure maya.cmds exists in __main__, it needs to be imported from within __main__. You can either do that by including the import statement in your callback, or by using MEL’s python command to import it in __main__ in one place. If you were just executing this code from the Script Editor then you’d be fine, but the assumption here is that you’re working on this code in a module of your own.
Adam said this on March 30, 2015 at 1:00 pm |
I am trying to follow from Extending GUI Classes, but when I execute AR_PolyOptionsWindow lines i get this:
# Error: global name ‘cmds’ is not defined
# Traceback (most recent call last):
# File “”, line 8, in
# File “D:\MayaPython\MayWorkspace\HelloPyDev\optwin.py”, line 7, in showUI
# win.create()
# File “D:\MayaPython\MayWorkspace\HelloPyDev\optwin.py”, line 24, in create
# if cmds.window(self.window, exists=True):
# NameError: global name ‘cmds’ is not defined #
Why is that?
Jose said this on May 5, 2015 at 3:21 am |
Nevermind
Just a very stupid move, great book!
Jose said this on May 13, 2015 at 6:13 pm |