Skip to content

Instantly share code, notes, and snippets.

@internetimagery
internetimagery / connections.py
Created November 24, 2015 10:21
Turning Mayas twin list output into a dictionary
import maya.cmds as cmds
sel = cmds.ls(sl=True)
conn = iter(cmds.listConnections(sel, c=True))
conn = dict(zip(conn, conn))
print conn
@internetimagery
internetimagery / IK_Orient.py
Last active December 12, 2015 06:25
IK-Like Orientation Setup. Aim constraint.
# IK Orientation Control
import pymel.core as pmc
import maya.api.OpenMaya as om
def message(text):
pmc.confirmDialog(t="Uh oh...", m=text)
class Orient(object):
""" Orient setup using IK-like system """
@internetimagery
internetimagery / lookup.py
Created December 16, 2015 12:55
numerical index in dict vs list vs tuple, speed test
import timeit
import random
import sys
def build():
for i in range(1000):
yield (i, random.random())
d = dict(build()) # numerical index
l = list(a[1] for a in build()) # Regular index
@internetimagery
internetimagery / report.py
Last active December 21, 2015 01:04
Simple Error reporting for Maya.Prompts user to send email with compact error report enclosed.
# Simple Error report mechanism squeezing into mailto: character limit
# Created By Jason Dixon. http://internetimagery.com
#
# Wrap the outermost function calls in the Report class
# As a decorator or as a context manager on the outermost function calls
# For instance, decorate your Main() function,
# or any function that is called directly by a GUI
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
@internetimagery
internetimagery / selection.py
Last active December 21, 2015 11:56
Make a keyframe selection in Maya.
# Contexturally make a selection.
# Created By Jason Dixon. http://internetimagery.com
#
# Wrap the outermost function calls in the Report class
# As a decorator or as a context manager on the outermost function calls
# For instance, decorate your Main() function,
# or any function that is called directly by a GUI
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
@internetimagery
internetimagery / offset.py
Last active December 22, 2015 15:21
Offset Constraint. Constrains one object (with animation) to another in time.
# Offset constraint for Maya
# Created By Jason Dixon. http://internetimagery.com
#
# Wrap the outermost function calls in the Report class
# As a decorator or as a context manager on the outermost function calls
# For instance, decorate your Main() function,
# or any function that is called directly by a GUI
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
@internetimagery
internetimagery / tri.py
Last active December 23, 2015 01:53
Pascals triangle
import collections
class Pascals_Triangle(collections.Sequence):
""" Build a triangle as indexes are requested """
tri = [(1,)]
def __len__(s): return len(s.tri)
def __repr__(s):
rows = [repr(a) for a in s.tri]
size = max(len(a) for a in rows)
return "\n".join(a.center(size) for a in rows)
@internetimagery
internetimagery / bounds.py
Created December 23, 2015 11:04
bezier bounding box
# http://stackoverflow.com/questions/2587751/an-algorithm-to-find-bounding-box-of-closed-bezier-curves
from __future__ import division
import math
def getBoundsOfCurve(x0, y0, x1, y1, x2, y2, x3, y3):
tvalues = []
bounds = [[], []]
points = []
@internetimagery
internetimagery / keyframe_test.py
Created January 2, 2016 21:33
Collecting keyframe times
# Testing gathering keyframe speeds
import timeit
import itertools
import collections
import maya.cmds as cmds
sel = cmds.ls(sl=True, type="transform")
if not sel: raise RuntimeError("Select something")
@internetimagery
internetimagery / dupe.py
Created January 12, 2016 12:54
Move duplicate files into a folder
# put in shebang here
from __future__ import print_function, division
"""
Take all duplicate files from decending directories and move
them into a new folder "Duplicates" in the working directory.
"""
import os
import sys