Last active
September 30, 2017 20:06
-
-
Save splinecraft/41dbbefe23f0da255f61eb7c87f93f83 to your computer and use it in GitHub Desktop.
anim_util work
This file contains hidden or 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 pm | |
| import maya.mel as mel | |
| import maya.cmds as cmds | |
| CORE_ATTRIBUTES = {'rx': 'rotateX', | |
| 'ry': 'rotateY', | |
| 'rz': 'rotateZ', | |
| 'tx': 'translateX', | |
| 'ty': 'translateY', | |
| 'tz': 'translateZ' | |
| } | |
| def timerange_selection(trim=True): | |
| """Checks the selected range in the time slider and returns a 2 item list with start/end of selection. | |
| If nothing is selected returns 0""" | |
| time_control = pm.lsUI(type='timeControl')[0] | |
| # check that there is a highlighted range, if not stop here | |
| if not pm.timeControl(time_control, q=True, rangeVisible=True): | |
| return [0] | |
| time_selected = pm.timeControl(time_control, q=True, rangeArray=True) | |
| # timeControl counts the frame past the selection as the last frame, which we may not want | |
| if trim: | |
| time_selected[-1] -= 1 | |
| return time_selected | |
| def frame_within_range(frame, timerange): | |
| return min(timerange) <= frame <= max(timerange) | |
| def time(frame): | |
| """Maya time flags are odd, require a tuple format so this returns that so you don't have to worry about | |
| formatting it as (10, ) etc""" | |
| return (frame,) | |
| def get_key_times(curve): | |
| """Returns list of keyframe times on curve""" | |
| return pm.keyframe(curve, query=True, timeChange=True) | |
| def get_key_values(curve): | |
| """Returns list of keyframe values on curve""" | |
| return pm.keyframe(curve, query=True, valueChange=True) | |
| def get_selected_channels(): | |
| """Returns a list of the selected channels in the channel box""" | |
| return pm.channelBox('mainChannelBox', q=True, selectedMainAttributes=True) | |
| def anim_layers_exist(): | |
| """Checks if anim layers exist in the scene""" | |
| base_anim_layer = pm.animLayer(query=True, root=True) | |
| if base_anim_layer is None: | |
| return False | |
| child_layers = pm.animLayer(base_anim_layer, query=True, children=True) | |
| if len(child_layers) == 0: | |
| return False | |
| return True | |
| def set_color(node, color=4): | |
| """Sets the draw override color""" | |
| pm.setAttr(node + '.overrideEnabled', True) | |
| pm.setAttr(node + '.overrideColor', color) | |
| return |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment