Skip to content

Instantly share code, notes, and snippets.

View splinecraft's full-sized avatar

Eric Luhta splinecraft

  • Vancouver, BC
View GitHub Profile
@splinecraft
splinecraft / timeline_selection.py
Created September 7, 2016 18:26
Query Maya timeline selection
# Method 1
from pymel.core import *
slider = mel.eval('$tmpVar=$gPlayBackSlider')
sliderFrames = ''.join([c for c in timeControl(slider, q=1, rng=1) if c in '1234567890:'])
sliderStart = int(sliderFrames.split(":")[0])
sliderEnd = int(sliderFrames.split(":")[1])
@splinecraft
splinecraft / import_not_in_path.py
Created September 7, 2016 18:29
Import file that isn't in python path
import imp
util = imp.load_source('util', '/Users/eric/Google Drive/Macbook Sync/Maya Tools/shapes/CurveShape.py')
@splinecraft
splinecraft / animation_hotkeys.py
Created September 7, 2016 18:36
Maya animation hotkeys
#--------------------------------------------------------------------------------------#
# sharpen in tangent
import pymel.core as pm
pm.keyTangent(edit=True, weightLock=False, lock=False, inWeight=.01)
# sharpen out tangent
import pymel.core as pm
pm.keyTangent(edit=True, weightLock=False, lock=False, outWeight=.01)
@splinecraft
splinecraft / select_curves_demo.py
Created September 7, 2016 18:39
select curves demo from DK
sel=pm.ls(sl=True)
print sel
curveList = pm.keyframe(q=True, sl=True, name=True)
print curveList
control_xform = pm.selected()[0]
curveList = control_xform.inputs()
@splinecraft
splinecraft / select_all_animated_nodes.py
Created September 7, 2016 18:42
select all animated nodes
"""
Select Animated Nodes
Here’s a quick script I threw together today that will take your selection, check if any of the nodes have animation curves attached to them, and then deselect all the nodes that aren’t animated. Leaving you only with the nodes that are animated. I say nodes because it will keep any node in Maya you have intially selected whether it’d be a transform, a shape, or a nParticle node. So, be careful with your initial selection and you won’t have to worry about what you get out in the end.
"""
objs = mc.ls(sl=True,dag=True)
print objs
animated = []
for obj in objs:
findAnimCurves = mc.listConnections(obj,source=True,type="animCurve")
@splinecraft
splinecraft / pymel_animation_examples.py
Last active September 30, 2017 20:19
Some pymel examples for working with animation
import pymel.core as pm
sel = pm.ls(sl=True)
attr_path = '{0}.{1}'.format(sel[0], 'ty')
key_frames = pm.keyframe(attr_path, q=True)
key_values = pm.keyframe( attr_path, q=True, vc=True)
in_tangents = pm.keyTangent( attr_path, q=True, itt=True)
@splinecraft
splinecraft / keyframe_randomizer.py
Created September 7, 2016 18:47
Maya keyframe randomizer
"""
http://blog.cameronleger.com/mel/keyrandomizer/
MAYA KEYFRAME RANDOMIZER
This is a Maya python script used for randomizing keyframe values or times. When applied over a range, a different randomization will be applied to each attribute and each key for it. Using the GUI you can select what attributes to modify, whether to modify them in space and/or time, and the ranges for modification. First, copy&paste this into the script editor, select all of it, and save it to your shelf. Then, select the objects you want to adjust their keyframes and run the script.
The first two checkboxes are for space / time modification. Spatial Keyframes will modify attribute values for each keyframe. Temporal Keyframes will modify the frame that the keyframes are on.
Min / Max Randomness is the amount to be applied to each value. The amount is added, so 0-1 will only produce positive alterations and -1-0 will only produce negative alterations. The value is a floating point number, so 0-1 will always randomly choose a decima
@splinecraft
splinecraft / keyframe_offsetter.mel
Created September 7, 2016 18:49
Maya Iterative keyframe offsetter
http://blog.cameronleger.com/mel/offsetkeys/
MAYA ITERATIVE KEYFRAME OFFSETTER
This is a small MEL script to copy, paste, and offset keyframes iteratively on multiple objects. First, copy the keyframes from the first object. Then, select the rest of the objects to paste the animation to. The offset value is how many frames to offset the animation for each object. The start value is the frame the entire animation should start on. For each object selected in the order that they are selected, it pastes the animation offset by the amount you chose per each object.
To use this script, you should paste the following into the MEL section of the Script Window, and then execute the code. Or you could drag the selected code in the MEL tab to the Shelf to create a shelf item for it.
if ( `window -exists window` )
deleteUI window;
window -title "keyOffset" window;
@splinecraft
splinecraft / evenlyDivisibleScaling.js
Created September 8, 2016 07:12
Find evenly divisible scales of animation lengths, for anim calculator
function findEvenlyDivisibleScaling(animLength) {
var even_scales = [];
for(i=1; i<100; i++) {
var scale = animLength * (i * 0.01);
if(scale % 1 === 0)
{
even_scales.push(i * 0.01);
}
@splinecraft
splinecraft / kwargs_example.py
Created September 19, 2016 04:37
Example of having default values and overriding them with kwargs From http://stackoverflow.com/questions/1098549/proper-way-to-use-kwargs-in-python
def testFunc( **kwargs ):
options = { 'option1' : 'default_value1',
'option2' : 'default_value2',
'option3' : 'default_value3', }
options.update(kwargs)
print options
testFunc( option1='new_value1', option3='new_value3' )
# {'option2': 'default_value2', 'option3': 'new_value3', 'option1': 'new_value1'}