Python in CG Production
Windows: make sure to install 64bit version of Python 3
IDE
An Integrated Development Environment (IDE) is an essential tool for software development. Offering numerous time-saving and productivity features, an IDE should provide the foundation for every TD's development environment.
IDEs for Python Development
Visual Studio Code References
What are Packages?
A single Python file is a module
A package is a folder containing Python files (modules) and an __init__.py file
The __init__.py file distinguishes it as a package. Otherwise, it is just a directory containing Python files.
Popular 3rd Party Packages
PySide2 - UI
NumPy - Scientific Computing
Pylint - Code Analysis
Django - Web Framework
Pillow - Image Manipulation
Installing Packages from PyPI use pip.
Virtual Environments
To find out where all the installed packages are located we can use the following command in an interactive session:
Creating Virtual Environments
The venv module provides support for creating and activating a virtual environment. This is available since Python 3.3 and it is the recommended method as of Python 3.5.
Standalone Qt Application (example)
By default the color palette for QT seems outdated, but can be changed fairly easily to a modern dark theme using the QPalette Class. Here we are mostly interested in the ColorRole. But first we need to define the style we want to use, in my case I picked "fusion".
Technically, we could go into the nitty-gritty and modify everything. All we have to do is look at the documentation for the QStyle class.
JSON (JavaScript Object Notation)
Standardized format for storing and exchanging data, including
Storing configurations
Managing metadata (e.g. assets or shots)
Communicating between different applications
Human readable and easy to understand
JSON and Python
Python has a build-in package called json for encoding and decoding JSON
Serialization - The process of encoding JSON
json.dump(data, file_name) or json.dumps(data)
Deserialization - The process of decoding JSON
json.load(file_name) or json.loads(json_string)
Automation with Sockets
Sockets are the endpoints of a two-way communication link between two programs running on the network
A client is the socket end that requests a connection
A server is the socket end that listens for and allows remote connections
Both the client and server can send and receive data
Maya doesn't allow direct connections, but we can use the IP address (local host) and a given port which can be a number between 1024 and 65535.
This can be added to the userSetup.py file in Library/Preferences/Autodesk/maya/2018/scripts/userSetup.py
like so:
The number given as name are based on the maya version e.g. 2018 and ending with a 0 for mel and a 1 for python.
BUFFER_SIZE = 4096 (usually, but can be changed)
Last updated