Skip to content

Instantly share code, notes, and snippets.

View splinecraft's full-sized avatar

Eric Luhta splinecraft

  • The Coalition Studio - Microsoft
  • Vancouver, BC
View GitHub Profile
@splinecraft
splinecraft / return_curve_list.py
Created December 6, 2016 00:33
Getting a list of curves - 2 ways
# from selected curves in graph editor
curves = pm.keyframe(q=True, selected=True, name=True)
print(curves)
"""
[u'IKSpine2_M_visibility_idle_mvmt_inputB', u'IKSpine2_M_translateX_idle_mvmt_inputB',
u'IKSpine2_M_translateY_idle_mvmt_inputB', u'IKSpine2_M_translateZ_idle_mvmt_inputB',
u'IKSpine2_M_rotate_idle_mvmt_inputBX', u'IKSpine2_M_rotate_idle_mvmt_inputBY',
u'IKSpine2_M_rotate_idle_mvmt_inputBZ', u'IKSpine2_M_scaleX_idle_mvmt_inputB',
u'IKSpine2_M_scaleY_idle_mvmt_inputB', u'IKSpine2_M_scaleZ_idle_mvmt_inputB',
@splinecraft
splinecraft / delete_keys.py
Created December 6, 2016 00:56
Set a key at the current frame and delete all other keys on selected controls/object
import pymel.core as pm
current_frame = pm.getCurrentTime()
curves = pm.findKeyframe(curve=True)
first_key = 0.0
last_key = 0.0
for curve in curves:
key = pm.findKeyframe(curve, which='first')
@splinecraft
splinecraft / anim_layers.py
Created December 8, 2016 20:43
Anim layers example to query and create new layer if it doesn't already exist From https://www.safaribooksonline.com/library/view/maya-programming-with/9781785283987/ch06s03.html
import maya.cmds as cmds
def makeAnimLayer(layerName):
baseAnimationLayer = cmds.animLayer(query=True, root=True)
foundLayer = False
if (baseAnimationLayer != None):
childLayers = cmds.animLayer(baseAnimationLayer, query=True, children=True)
@splinecraft
splinecraft / get_namespace.py
Created December 14, 2016 23:40
Get namespace of selected
namespace = pm.selected()[0].namespace()
@splinecraft
splinecraft / footfall.py
Created December 15, 2016 08:33
Calculate counter keys on feet for run/walk cycles
"""
Script for setting counter translate keys on the feet for walk/run cycles. Select the 2 keys on the curve(s)
of the foot Tz and run. It assumes you have a master curve with the speed for 1 second on the main control.
"""
import pymel.core as pm
class Footfall:
"""
@splinecraft
splinecraft / get_distance.py
Last active September 30, 2017 20:15
Get world space distance between two objects in Maya
import pymel.core as pm
import pymel.core.datatypes as dt
def get_distance(object1, object2):
# use rotation pivot to get the position since frozen transforms will affect
# where the object "is"
position1 = pm.xform(object1, query=True, worldSpace=True, rotatePivot=True)
position2 = pm.xform(object2, query=True, worldSpace=True, rotatePivot=True)
v1, v2 = dt.Vector(position1), dt.Vector(position2)
@splinecraft
splinecraft / get_selected_channels.py
Last active September 30, 2017 20:15
Get selected attributes in channel box
import maya.mel as mel
def get_selected_channels():
#fetch maya's main channelbox
channelBox = mel.eval('global string $gChannelBoxName; $temp=$gChannelBoxName;')
attrs = cmds.channelBox(channelBox, q=True, sma=True)
if not attrs:
return []
return attrs
@splinecraft
splinecraft / glitchfinder.py
Last active September 30, 2017 20:15
glitchfinder_v2
from pymel.core import *
import pymel.core as pm
import json
from collections import Counter
"""
Glitch finder version 1.0 by Eric Luhta, ericl@splinecraft.com
Creatist: Eric Luhta
@splinecraft
splinecraft / scalist_v4.py
Created January 3, 2017 08:00
scalist new ui
"""
#######################################################################
scale_keys v1.4
by Eric Luhta
Last update: 12/20/2016
Makes scaling curves in the graph editor vastly more powerful and simple.
Helpful info can be found in the tool's "About" tab.
@splinecraft
splinecraft / snapist.py
Created January 4, 2017 17:33
snap keys
import pymel.core as pm
def get_snap_value(values, last_sel):
differences = []
for value in values:
differences.append(abs(last_sel - value))
return min(differences)
def selection_ok(curve):