Chapter 4. Leveraging Context Managers and Decorators in Maya

Context managers and decorators are two Python features that open up many powerful programming patterns. Many of these end up being incredibly useful in Maya, allowing us to map the archaic, imperative style of Maya command calls onto Pythonic code using flexible, modern idioms.

In this chapter, we will learn what context managers and decorators are, why they are useful, how they work, and when to use one instead of the other. After that, we'll build a number of simple context managers for safely modifying scene state. Using what we've learned, we will work on two projects: a context manager for denormalizing vertex skinning, and a decorator to record metrics. We will close out the ...

Get Practical Maya Programming with Python now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.