Skip to content

Instantly share code, notes, and snippets.

View theodox's full-sized avatar

Steve Theodore theodox

View GitHub Profile
@theodox
theodox / melfunction.py
Last active August 25, 2019 19:49
Tools for wrapping rogue mel commands
melfunction.py
"""
Provides tools for wrapping mel commands for more Pythonic access.
Note this is a supplement to maya.cmds, not a replacement for it! This is intended to provide
similar coverage for un-translated MEL or commands fron plugins which don't respect the
ordinary cmds conventions.
Legalese:
@theodox
theodox / bad_fbx.py
Created October 25, 2014 21:54
illustration of how fbx plugins work
import maya,cmds as cmds
# All the command defined in the plugin show up in Maya.cmds if the plugin
# was loaded at startup....
# alas, they don't work like the builtins.....
cmds.FBXExport(f = "path/to/file.fbx")
# RuntimeError: Use syntax: FBXExport -f "filename" [-s]
@theodox
theodox / FBX Wrapper.py
Last active December 19, 2021 12:05
FBXWrapper
'''
FBXWrapper
This module provides a python wrapper for every method exposed in the FBX plugin.
The arguments for the calls are the same as for the equivalent mel calls, however they can be passed with typical
python syntax, which is translated to mel-style flags and arguments under the hood. The actual flags and arguments
are documented here:
usage:
import os
import shutil
import site
# source paths and local storage in environment vars
# switch toolsets by changing these before
# running maya
dist_file = os.environ['MAYA_TOOLS_SRC']
maya_tools = os.environ['MAYA_TOOLS_LCL']
last_mod_time = -1
'''
This is the default UndeadLabs maya UserSetup.py. It should be copied into
one of the user's MAYA_SCRIPT_DIR folders (typically, the one for the
current version, like '2014x64', but it works in the generic one as well)
'''
import os
import site
import sys
ZIP_NAME = os.environ.get('MAYA_ZIP', 'ulmaya.zip')
"""
ul.paths.py
mimics the site module: process .pth files identically for zip and loose file distributions
"""
import zipfile
import sys
import os
import logging
@theodox
theodox / WebFinderExample.py
Last active August 29, 2015 14:01
using webfinder and webloader
sys.path_hooks.append(WebFinder)
sys.path.append("http://www.inference.phy.cam.ac.uk/mackay/python/compression/huffman")
# with the url on the path, just use import
import Example
print Example.__path__
#['http://www.inference.phy.cam.ac.uk/mackay/python/compression/huffman/Example.py']
# the module's __path__ will point at the url, but __file__ points at the cached
# file on disk
# usess the same imports as WebFinder.py
class WebLoader(object):
'''
Import loader (see http://pymotw.com/2/sys/imports.html for background)
which loads modules cached by a WebFinder using imp.load_source
'''
def __init__(self, url, filepath, name):
self.url = url
self.name = name
'''
web_shim.py
Exposes a custom module loader and importer which allow for download, cache and
load of python modules stored on an HTTP server
To activate, add the class to sys.path_hooks:
sys.path_hooks.append(WebFinder)
'''
@theodox
theodox / mayaPyManager.py
Last active September 23, 2024 22:15
Exposes the MayaPyManager class, which is used to run instances of MayaPy with explict control over paths and environment variables. A Manager can run scripts, modules, or command strings in a separate MayaPy environment; results and errors are captured and returned.
'''
Exposes the MayaPyManager class, which is used to run instances of MayaPy with explict control over paths and environment variables. A Manager can run scripts, modules, or command strings in a separate MayaPy environment; results and errors are captured and returned.
Typical uses might be:
- running unit tests
- running a copy of Maya.standalone as a headless RPC server with StandaloneRPC https://github.com/theodox/standaloneRPC
- spawning multipe copies of maya to batch process files in parallel on a multi-core machine
- do any of the above on multiple maya versions concurrently