1. Trang chủ
  2. » Công Nghệ Thông Tin

Practical maya programming with python; unleash the power of python in maya and unlock your creativity

592 258 0

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

THÔNG TIN TÀI LIỆU

Thông tin cơ bản

Định dạng
Số trang 592
Dung lượng 2,17 MB

Nội dung

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 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 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 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 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 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 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 Python Automatically killing the server Creating a basic Maya server Running code at Maya startup Understanding eval and exec Adding support for eval and exec Adding support for exception handling Adding support for timeouts Adding support for the client-server handshake Practical uses and improvements Batch processing using Maya PyMEL object query string, creating for / Creating a query string for a PyMEL object PyMEL performance improving / Improving the performance of PyMEL defining / Defining performance refactoring / Refactoring for performance inner loops, rewriting to use maya.cmds / Rewriting inner loops to use maya.cmds PyNodes about / PyNodes all the way down PyQt about / Introducing Qt, PyQt, and PySide and PySide, supporting / Supporting PySide and PyQt PySide about / Introducing Qt, PyQt, and PySide installing / Installing PySide URL / Installing PySide and PyQt, supporting / Supporting PySide and PyQt Python types / Understanding Python and MEL types about / PyNodes all the way down leveraging / Leveraging Python, which is better than MEL Maya, launching from / Launching Maya from Python URL / Engaging with the wider community best practices / The args and kwargs parameters, String formatting, String concatenation, Raw strings and string literals, Unicode strings, Using the doctest module, Using the GitHub repository for this book Python client using / Using a Python client and Maya server Python Decorator Library URL / Using Python's decorator library Python Developer's Guide URL / Differentiating OSS from script download sites Python distributions working with / Working with Python distributions in Maya source distribution, adding to Maya / Adding a source distribution to Maya egg, adding to Maya / Adding an egg or wheel to Maya wheel, adding to Maya / Adding an egg or wheel to Maya binary distributions, using on Windows / Using binary distributions on Windows pip, used for installing thirdparty modules / Using pip to install thirdparty modules Python Enhancement Proposal (PEP) about / Learning to use list comprehensions Python file running, as script / Running a Python file as a script Python library benefits / Comparing the OpenMaya and scripting solutions Python metaprogramming demystifying / Demystifying Python metaprogramming type creation / Rethinking type creation type function, exploring / Exploring the type function declarative code / The importance of being declarative Python Package Index about / Using Python's decorator library Python Package Index (PyPI) using / Using the Python Package Index URL / Using the Python Package Index URL, for mock library / Adding a source distribution to Maya Python plugin defining / The life of a Python plugin PyZMQ about / Installing ZeroMQ URL / Installing ZeroMQ Q QApplication class about / Introducing the QApplication class Qt about / Introducing Qt, PyQt, and PySide Qt Designer using / Avoid the use of ui files Qt layouts about / Introducing Qt layouts Qt main windows about / Understanding Qt main windows and sorting Qt object getting, from Maya path / Getting the Qt object from a Maya path qtshim.py module QtCore namespace / Supporting PySide and PyQt QtGui namespace / Supporting PySide and PyQt Signal class / Supporting PySide and PyQt wrapinstance function / Supporting PySide and PyQt Qt signals about / Introducing Qt signals Qt sorting about / Understanding Qt main windows and sorting Qt widgets about / Introducing Qt widgets Qt window making, child of Maya window / Making a Qt window the child of Maya's window query string creating, for PyMEL object / Creating a query string for a PyMEL object R %r sequence / String formatting race condition about / The client-server handshake raise statement about / Explaining try/catch/finally flow control Raven client URL / Capturing locals raw strings about / Raw strings and string literals read-copy-update about / Dealing with expensive and mutable state refactor about / Code is never complete refactoring about / Learning how to refactor reference counting about / Introducing context managers reload function about / Using sys.excepthook in Maya using / Using Python's reload function with GUIs remote procedure call (RPC) about / Choosing what the server does remove_selected function / Refactoring for performance REPL leveraging / Leveraging the REPL about / Leveraging the REPL request-reply Maya, controlling through / Controlling Maya through request-reply demonstrating, with ZeroMQ / Demonstrating request-reply with ZeroMQ request-reply automation system, building about / Building the request-reply automation system Python package, creating / Creating a Python package Maya, launching from Python / Launching Maya from Python server, killing automatically / Automatically killing the server basic Maya server, creating / Creating a basic Maya server code, running at Maya startup / Running code at Maya startup eval statement / Understanding eval and exec exec statement / Understanding eval and exec support, adding for eval / Adding support for eval and exec support, adding for exec / Adding support for eval and exec support, adding for exception handling / Adding support for exception handling support, adding for timeouts / Adding support for timeouts support, adding for client-server handshake / Adding support for the client-server handshake request-response about / Controlling Maya through request-reply reStructured Text about / Understanding docstrings and reStructured Text rules, error handling about / Golden rules of error handling critical path, focusing / Focus on the critical path tool distribution, avoiding / Keep the end user in mind errors, catching / Only catch errors you can handle partial mutations, avoiding / Avoid partial mutations S %s sequence / String formatting s. dict attribute about / Dicts all the way down safe_setparent utility function extracting / Extracting the safe_setparent utility function script download sites OSS, differentiating from / Differentiating OSS from script download sites scripting solutions and OpenMaya, comparing / Comparing the OpenMaya and scripting solutions selection behavior about / Identifying anti-patterns of composability Sentry server URL / Capturing locals serializer about / Serializing requests and responses server about / Using a Python client and Maya server running, in Maya GUI session / Running a server in a Maya GUI session set_file_prompt context manager building / Building the set_file_prompt context manager set_namespace_active context manager building / Building the set_namespace_active context manager set_renderlayer_active context manager building / Building the set_renderlayer_active context manager shapes drawing, through inheritance creation / Introducing inheritance by drawing shapes shared normals / Setting mesh normals Simplified Wrapper and Interface Generator (SWIG) about / Understanding the OpenMaya bindings URL / Understanding the OpenMaya bindings site directory creating, for third party modules / Creating a site directory for thirdparty modules explaining / Explaining the site directory creating, for Maya / Creating a new site directory for Maya establishing, at startup / Establishing the site directory at startup skeleton converter library coding / Writing a skeleton converter library docstring, writing / Writing the docstring and pseudocode pseudocode, writing / Writing the docstring and pseudocode docstring, using / Understanding docstrings and reStructured Text reStructured Text, using / Understanding docstrings and reStructured Text implementation, writing / Writing the first implementation implementation, breaking / Breaking the first implementation contract / Understanding interface contracts safe_setparent utility function, extracting / Extracting the safe_setparent utility function refactoring / Learning how to refactor node to joint conversion, simplifying / Simplifying the node to joint conversion closures, using / Learning how to use closures node connections, dealing with / Dealing with node connections namespaces, dealing with / Dealing with namespaces wrapping up / Wrapping up the skeleton converter sound player library creating / Creating the sound player library source code management (SCM) / Starting an open source project source distribution adding, to Maya / Adding a source distribution to Maya Sphinx project URL / Designing Maya Python code for open source SQL Alchemy URL / The importance of being declarative startup site directory, establishing at / Establishing the site directory at startup statement / Understanding eval and exec static methods / Adding support for methods status codes about / Handling exceptions between client and server string concatenation about / String concatenation string formatting about / Creating an introspection function, String formatting string literals about / Raw strings and string literals subroutine inverting / Inverting the subroutine superclass about / Understanding Python and MEL types sys.excepthook about / Understanding sys.excepthook using, in Maya / Using sys.excepthook in Maya sys.excepthook function / Understanding sys.excepthook sys.exc_info() function about / Explaining the exc_info tuple T tail function writing, for composable code / Writing head and tail functions TDD adopting / Adopting Test-Driven Development Test Driven Development (TDD) about / Creating a query string for a PyMEL object thirdparty modules about / Defining what a thirdparty module is thirdparty modules, putting in thirdparty folder drawbacks / Adding a source distribution to Maya third party modules site directory, creating for / Creating a site directory for thirdparty modules top level menu creating / Creating a top-level menu traceback about / Explaining traceback objects traceback2 module URL / Capturing locals traceback objects / Explaining traceback objects Trello URL / Moving beyond e-mail try/catch/finally flow control / Explaining try/catch/finally flow control tuple_to_mpoint function / Building a mesh type about / Exploring Maya and PyMEL, Explaining types creating / Dicts all the way down custom types used, to simplify code / Using custom types to simplify code inheritance creation, by drawing shapes / Introducing inheritance by drawing shapes type function about / Understanding Python and MEL types exploring / Exploring the type function type hierarchies about / Introducing Qt widgets types, MEL / Understanding Python and MEL types types, Python / Understanding Python and MEL types U unbound method / Adding support for methods undo blocks leveraging / Leveraging undo blocks undoInfo drawbacks / Leveraging undo blocks undo_chunk context manager writing / Writing the undo_chunk context manager undo_on_error context manager writing / Writing the undo_on_error context manager unhandled exceptions about / Living with unhandled exceptions Unicode strings about / Unicode strings unit about / Defining composability user-defined scripts / Choosing a startup configuration mechanism user interface adding / Adding a user interface utility functions about / Extracting the safe_setparent utility function V vertexArray parameter / Navigating the Maya API Reference W What-You-See-Is-What-You-Get (WYSIWYG) / Avoid the use of ui files What If Two Programs Did This rule about / Obeying the What If Two Programs Did This rule widget font, menu changing / Changing the font of a widget widgets styling, alternative methods / Using alternative methods to style widgets Windows binary distributions, using on / Using binary distributions on Windows Windows Presentation Foundation / Avoid the use of ui files window widget defining / Defining control, container, and window widgets WinForms / Avoid the use of ui files with_unit context manager building / Building the with_unit context manager Z ZeroMQ installing / Installing ZeroMQ request-reply, demonstrating with / Demonstrating request-reply with ZeroMQ ZMQ-The Guide URL / Demonstrating request-reply with ZeroMQ ... 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... Creating a Maya Python plugin The life of a Python plugin Creating the sound player library Creating the plugin file Reloading plugins Adding a command flag Comparing the OpenMaya and scripting... 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

Ngày đăng: 04/03/2019, 16:43

TỪ KHÓA LIÊN QUAN

TÀI LIỆU CÙNG NGƯỜI DÙNG

TÀI LIỆU LIÊN QUAN