Skip to content

Instantly share code, notes, and snippets.

@danbradham
danbradham / maya_ui.py
Last active January 30, 2024 08:43
Maya Dockable Mixin Example
from PySide2 import QtWidgets, QtCore
from maya.app.general.mayaMixin import MayaQWidgetDockableMixin
from maya import OpenMayaUI
# Compatability
try:
long
except NameError:
long = int
@danbradham
danbradham / make_dynamic.py
Created January 26, 2019 01:06
Make it dynamic
from maya import cmds, mel
from contextlib import contextmanager
from mayakit.tags import tag, untag, query, search, message, unmessage, connect
@contextmanager
def selection(nodes=None):
old_selection = cmds.ls(sl=True)
try:
# -*- coding: utf-8 -*-
from __future__ import absolute_import, division, print_function
from tinyrpc import spawn, init_maya
# Simple rpc example
# Opens rpc on localhost at port 8000 using the current python interpreter
rpc = spawn()
@danbradham
danbradham / extraclick.py
Created February 21, 2018 21:58
Make Armin Ronacher's excellent click library even more excellent.
# -*- coding: utf-8 -*-
'''
extraclick.py
==============
Make Armin Ronacher's excellent click library even more excellent.
- ListOption: click.Option subclass with a custom parser that eats all
arguments until the next option is found. This allows for the same sort
@danbradham
danbradham / regenerator.py
Last active February 21, 2018 21:39
Python 2.7 Recursive Generator
def regenerator(generator_fn):
'''A decorator for generators. When a generator is yielded, it's
items are yielded one by one. This allows generators to be recursive
without requiring the yield from syntax of Python 3.3+.
Examples:
>>> @regenerator
... def count_down(number):
... if number < 0:
@danbradham
danbradham / test_dir_mtime.py
Created January 24, 2018 01:50
Test conditions under which st_mtime of a directory changes
# -*- coding: utf-8 -*-
'''
This module tests the circumstances under which a directory's st_mtime changes.
Precision is determined by the current file system. On Windows with NTFS the
tests will pass when the time between changes is as low as 0.01 seconds. If
you set the INTERVAL to 0 you'll discover how inconsistent the tests become.
On Unix based systems with other file systems the time between changes must
increase in order for the tests to pass, in the worst case up to 2 seconds.
Runs with a default SLEEP_INTERVAL of 0.1 seconds. You can pass a different
@danbradham
danbradham / extract_particles.py
Last active October 24, 2020 00:39
Extract Maya nParticles as Spheres
'''
Extract particles as polySpheres.
Supports:
position, rotationPP, rgbPP, and radiusPP
'''
from maya import cmds
class Sphere(object):
@danbradham
danbradham / get_parent_process.py
Created December 24, 2017 03:33
psutil get parent process
# -*- coding: utf-8 -*-
import psutil
def get_parent_process(ok_names, limit=10):
'''Walk up the process tree until we find a process we like.
Arguments:
ok_names: Return the first one of these processes that we find
'''
@danbradham
danbradham / simple_collisions.py
Created October 23, 2017 20:46
Simple collision detection node network for Maya
from maya import cmds
def simple_collision_check(obj_xform, collider_shape):
'''
Create a node network that checks whether an objects xform is colliding with a mesh. Returns a condition node where outputX, Y, and Z are 1
for colliding and 0 when not colliding.
:param obj_xform: Path to object transform
:param collider_shape: Path to mesh transform
@danbradham
danbradham / fstrings.py
Last active March 7, 2017 17:55
f-strings backport...sorta
# -*- coding: utf-8 -*-
'''
f-strings backport...sorta
==========================
What it looks like::
>>> x = 'Hello, World...'
>>> f('{x}')
'Hello, World...'