This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os | |
import os.path | |
class Temp_Path(str): | |
def __del__(s): | |
if os.path.isfile(s): os.remove(s) | |
def __getattribute__(s, k): | |
if k[0] == "_": return str.__getattribute__(s, k) | |
raise AttributeError, "\"%s\" cannot be modified with \"%s\"" % (s.__class__.__name__, k) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Timer(object): | |
verbose = False | |
def __init__(s, name): | |
from time import time | |
s.time = time | |
s.name = name | |
def __enter__(s): s.start = s.time() | |
def __exit__(s, *err): | |
if s.verbose: print "%s...\t\tElapsed time: %sms." % (s.name, (s.time() - s.start) * 1000) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import shutil | |
import os.path | |
import zipfile | |
import collections | |
try: | |
import zlib | |
compress = zipfile.ZIP_DEFLATED | |
except ImportError: | |
compress = zipfile.ZIP_STORED |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import traceback | |
try: | |
pass | |
# Do scriptjob code in here. Since Scriptjobs do not display exceptions, do it ourselves. | |
except: | |
print traceback.format_exc() | |
raise |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import time | |
import threading | |
import collections | |
import maya.cmds as cmds | |
import maya.utils as utils | |
class window(object): | |
def __init__(s): | |
name = "Testwindow" | |
s.maya = Maya() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
try: | |
import cPickle as pickle | |
except ImportError: | |
import pickle | |
class Dict(dict): | |
""" | |
Dict that tracks changes. Changes = (New, Changed, Removed) | |
""" | |
def __init__(s, *args, **kwargs): |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import collections | |
class DB(collections.MutableMapping): | |
""" Database Interface """ | |
_default = object() | |
def __init__(s): | |
s._cnt = 0 | |
s._del = set() | |
with s: s._data = dict((a, s._default) for a in s.initkeys()) | |
def __enter__(s): |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# http://www.peterbe.com/plog/uniqifiers-benchmark | |
def unique(lst): | |
a = set(lst) | |
return [b for b in lst if b in a and not a.remove(b)] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import math, collections | |
class Vector(tuple): | |
__slots__ = () | |
def __neg__(s): return s.__class__(-a for a in s) | |
def __pos__(s): return s.__class__(+a for a in s) | |
def __ne__(s, v): return False if s == v else True | |
magnitude = property(lambda s: math.sqrt(sum(s * s))) # |s| | |
def __nonzero__(s): return 1 != len(set(a for a in s if not a)) | |
def __add__(s, v): return s.__class__(a + b for a, b in zip(s, v)) | |
def __div__(s, v): return s.__class__(a / b for a, b in zip(s, v)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import maya.cmds as cmds | |
sel = cmds.ls(sl=True) | |
conn = iter(cmds.listConnections(sel, c=True)) | |
conn = dict(zip(conn, conn)) | |
print conn |