Practical error handling in Maya
Most of these golden rules are true in Python in general, as well as most other programming languages with exceptions. However, using Python in Maya is a different environment. There are some additional tools and constraints available. In this section, we'll go through some of the unique problems we face in Maya, and what can be done to mitigate each problem.
Dealing with expensive and mutable state
The biggest problem with error handling in Maya is that its overall design significantly constrains the choices of any system built on top of it. Consider the following script that lowercases the fileTextureName
(ftn
) attribute of all the file nodes in the scene:
>>> for f in pmc.ls(type='file'): ... f.ftn.set(f.ftn.get().lower()) ...
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.