Practical Maya Programming with Python
eBook - ePub

Practical Maya Programming with Python

  1. 352 pages
  2. English
  3. ePUB (mobile friendly)
  4. Available on iOS & Android
eBook - ePub

Practical Maya Programming with Python

Book details
Book preview
Table of contents
Citations

About This Book

In Detail

Autodesk Maya is a 3D computer graphics software. It offers a vast and flexible set of features utilizing Python. It is not difficult to get started using Python in Autodesk Maya, but it can be difficult to go from writing procedural, MEL-inspired tools to building the powerful yet simple systems that Python promises.

Practical Maya Programming with Python will help you master both Python and Maya. With thorough explanations, illustrative examples, and complete sample projects, you will learn how to use Python to charm Maya into obeying your every command.  Practical Maya Programming with Python will teach you how PyMEL works as well as how to deal with errors and write composable code in Python.

Approach

"Practical Maya Programming with Python" is a practical tutorial packed with plenty of examples and sample projects which guides you through building reusable, independent modules and handling unexpected errors.

Who this book is for

If you are a developer looking to build a powerful system using Python and Maya's capabilities, then this book is for you. Practical Maya Programming with Python is perfect for intermediate users with basic experience in Python and Maya who want to better their knowledge and skills.

Frequently asked questions

Simply head over to the account section in settings and click on “Cancel Subscription” - it’s as simple as that. After you cancel, your membership will stay active for the remainder of the time you’ve paid for. Learn more here.
At the moment all of our mobile-responsive ePub books are available to download via the app. Most of our PDFs are also available to download and we're working on making the final remaining ones downloadable now. Learn more here.
Both plans give you full access to the library and all of Perlego’s features. The only differences are the price and subscription period: With the annual plan you’ll save around 30% compared to 12 months on the monthly plan.
We are an online textbook subscription service, where you can get access to an entire online library for less than the price of a single book per month. With over 1 million books across 1000+ topics, we’ve got you covered! Learn more here.
Look out for the read-aloud symbol on your next book to see if you can listen to it. The read-aloud tool reads text aloud for you, highlighting the text as it is being read. You can pause it, speed it up and slow it down. Learn more here.
Yes, you can access Practical Maya Programming with Python by Robert Galanakis in PDF and/or ePUB format, as well as other popular books in Ciencia de la computación & Medios digitales. We have over one million books available in our catalogue for you to explore.

Information

Year
2014
ISBN
9781849694728

Practical Maya Programming with Python


Table of Contents

Practical Maya Programming with Python
Credits
About the Author
About the Reviewers
www.PacktPub.com
Support files, eBooks, discount offers and more
Why Subscribe?
Free Access for Packt account holders
Preface
What this book covers
What you need for this book
Who this book is for
Conventions
Reader feedback
Customer support
Downloading the example code
Errata
Piracy
Questions
1. Introspecting Maya, Python, and PyMEL
Creating your library
Using the interpreter
Finding a place for our library
Choosing a development root
Creating a function in your IDE
Reloading code changes
Exploring Maya and PyMEL
Creating an introspection function
Understanding Python and MEL types
Using the method resolution order
PyNodes all the way down
Understanding PyMEL data and math types
Leveraging the REPL
Building the pmhelp function
Creating a query string for a PyMEL object
Creating more tests
Adding support for modules
Adding support for types
Adding support for methods
Adding support for functions
Adding support for non-PyMEL objects
Designing with EAFP versus LBYL
Code is never complete
Opening help in a web browser
Summary
2. Writing Composable Code
Defining composability
Identifying anti-patterns of composability
Avoiding the use of Boolean flags
Evolving legacy code into composable code
Rewriting code for composability
Getting the first item in a sequence
Writing head and tail functions
Learning to use list comprehensions
Implementing is_exact_type
Saying goodbye to map and filter
Writing a skeleton converter library
Writing the docstring and pseudocode
Understanding docstrings and reStructured Text
Writing the first implementation
Breaking the first implementation
Understanding interface contracts
Extracting the safe_setparent utility function
Learning how to refactor
Simplifying the node to joint conversion
Learning how to use closures
Dealing with node connections
Dealing with namespaces
Wrapping up the skeleton converter
Writing a character creator
Stubbing out the character creator
Implementing convert_hierarchies_main
Implementing convert_hierarchies
Decomposing into composable functions
Implementing convert_hierarchy
Supporting inevitable modifications
Improving the performance of PyMEL
Defining performance
Refactoring for performance
Rewriting inner loops to use maya.cmds
Summary
3. Dealing with Errors
Understanding exceptions
Introducing exception types
Explaining try/catch/finally flow control
Explaining traceback objects
Explaining the exc_info tuple
Living with unhandled exceptions
Handling exceptions at the application level
Golden rules of error handling
Focus on the critical path
Keep the end user in mind
Only catch errors you can handle
Avoid partial mutations
Practical error handling in Maya
Dealing with expensive and mutable state
Leveraging undo blocks
Dealing with Maya's poor exception design
Leveraging the Maya application
Dealing with the Maya application
Leveraging Python, which is better than MEL
Building a high-level error handler
Understanding sys.excepthook
Using sys.excepthook in Maya
Creating an error handler
Improving the error handler
Inspecting Python code objects
Adding filtering based on filename
Assembling the contents of an error e-mail
Sending the error e-mail
Installing the error handler
Obeying the What If Two Programs Did This rule
Improving the error handler
Adding a user interface
Using a background thread to send the e-mail
Moving beyond e-mail
Capturing locals
Attaching log files
Summary
4. Leveraging Context Managers and Decorators in Maya
Inverting the subroutine
Introducing decorators
Explaining decorators
Wrapping an exporter with a decorator
Introducing context managers
Writing the undo_chunk context manager
Writing the undo_on_error context manager
Contrasting decorators and context managers
Context managers for changing scene state
Building the set_file_prompt context manager
Building the at_time context manager
Building the with_unit context manager
Building the set_renderlayer_active context manager
Building the set_namespace_active context manager
Improving on future versions of Maya
Creating the denormalized_skin context manager
Safely swapping vertex influences
Addressing performance concerns
Creating a decorator to record metrics
Getting a unique key
Recording duration
Reporting duration
Handling errors
Advanced decorator topics
Defining decorators with arguments
Decorating PyMEL attributes and methods
Stacking decorators
Using Python's decorator library
Doing decorators the right way
Summary
5. Building Graphical User Interfaces for Maya
Introducing Qt, PyQt, and PySide
Introducing Qt widgets
Introducing Qt layouts
Understanding Qt main windows and sorting
Introducing Qt signals
Establishing rules for crafting a GUI
Prefer pure PySide GUIs where possible
Use command-style UI building where necessary
Avoid the use of .ui files
Installing PySide
Supporting PySide and PyQt
Creating the hierarchy converter GUI
Creating the window
Running a Python file as a script
Introducing the QApplication class
Understanding the event loop
Running your GUI
Designing and building your GUI
Defining control, container, and window widgets
Adding the rest of the widgets
Hooking up the application to be effected by the GUI
Hooking up the GUI to be effected by the application
Simulating application events
Considering alternative implementations
Integrating the tool GUI with Maya
Opening the tool GUI from Maya
Getting the main Maya window as a QMainWindow
Making a Qt window the child of Maya's window
Using Python's reload function with GUIs
Emitting a signal from Maya
Connecting Maya to a signal
Verifying the hierarchy converter works
Working with menus
Creating a top-level menu
Getting the Qt object from a Maya path
Changing the font of a widget
Marking menus as new
Creating a test case
Adding a persistence registry
Verifying the new menu marker works
Using alternative methods to style widgets
Working with Maya shelves
Summary
6. Automating Maya from the Outside
Controlling Maya through request-reply
Using a Python client and Maya server
Controlling Python through exec and eval
Handling problems with IPC
Installing ZeroMQ
Demonstrating request-reply with ZeroMQ
Explaining connection strings, ports, bind, and connect
Designing the automation system
Pairing one client and one server
Bootstrapping the server from the client
The client-server handshake
Defining the server loop
Serializing requests and responses
Choosing what the server does
Handling exceptions between client and server
Understanding the Maya startup routine
Using batch mode versus GUI mode
Choosing a startup configuration mechanism
Using command line options
Using environment variables
Building the request-reply automation system
Creating a Python package
Launching Maya from...

Table of contents

  1. Practical Maya Programming with Python