Book Image

Practical Maya Programming with Python

By : Robert Galanakis
Book Image

Practical Maya Programming with Python

By: Robert Galanakis

Overview of this book

Table of Contents (17 chapters)
Practical Maya Programming with Python
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

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 the prompt keyword. Using False disables most file prompts. However, this flag is not a customization flag that is used when the file command is invoked. It is a stateful flag that must be set separately from other calls to file. To safely call file with...