7/15/2017 - 12:10 AM

anim_util work

anim_util work

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)