Last active
August 2, 2016 15:51
-
-
Save tokejepsen/f3da7bddcec219f81108 to your computer and use it in GitHub Desktop.
Maya: Nondestructive holds
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 pymel.core as pc | |
import pymel.core.animation as pca | |
import pymel.core.nodetypes as pcn | |
import maya.mel | |
# create animation layer | |
if pc.ls(selection=True): | |
anim_layer = pca.animLayer(addSelectedObjects=True) | |
pc.rename(anim_layer, 'baked_secondary_keys') | |
anim_layer.override.set(True) | |
anim_layer.mute.set(True) | |
else: | |
pc.warning('No nodes selected!') | |
# get frame range | |
aPlayBackSliderPython = maya.mel.eval('$tmpVar=$gPlayBackSlider') | |
frame_range = None | |
if pc.timeControl(aPlayBackSliderPython, q=True, rangeVisible=True): | |
frame_range = pc.timeControl(aPlayBackSliderPython, q=True, rangeArray=True) | |
else: | |
frame_range = [pc.playbackOptions(animationStartTime=True, q=True), | |
pc.playbackOptions(animationEndTime=True, q=True)] | |
# storing current time for later | |
current_time = pca.currentTime(q=True) | |
# baking stepped keys on every second frame | |
for node in pc.ls(selection=True): | |
for f in range(int(frame_range[0]), int(frame_range[1]), 2): | |
pca.currentTime(f) | |
pca.setKeyframe(node, inTangentType='linear', outTangentType='step', animLayer=anim_layer.name()) | |
# animating weight on animation layer | |
if pc.ls(selection=True): | |
pca.currentTime(frame_range[0]-1) | |
anim_layer.weight.set(0) | |
pca.setKeyframe(anim_layer, attribute='weight') | |
pca.currentTime(frame_range[0]) | |
anim_layer.weight.set(1) | |
pca.setKeyframe(anim_layer, attribute='weight') | |
pca.currentTime(frame_range[1]) | |
anim_layer.weight.set(1) | |
pca.setKeyframe(anim_layer, attribute='weight') | |
pca.currentTime(frame_range[1] + 1) | |
anim_layer.weight.set(0) | |
pca.setKeyframe(anim_layer, attribute='weight') | |
#restoring current time | |
pca.currentTime(current_time) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment