O'Reilly logo

Practical Maya Programming with Python by Robert Galanakis

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Context managers for changing scene state

One frustrating aspect of Maya's design, from a coding perspective at least, is the single global scene and application state. To ensure state is changed and restored effectively, we can use context managers. There are a few common or interesting areas where we may want to apply them.

You can put all of the context managers we create in the following sections into mayautils.py. For the most part, their usage follows the same patterns we've already seen, so I've chosen not to clutter the chapter with demonstrations. The code files with this book include tests you can run to see them in action.

Building the set_file_prompt context manager

One often overlooked flag on the bloated maya.cmds.file command is

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required