def reset_channels(nodes=None,selectedChannels=False, transformsOnly=False, excludeChannels=None, keyableOnly=False): ''' Modified from Morgan Loomis' great reset call to expand options... ''' gChannelBoxName = mel.eval('$temp=$gChannelBoxName') _reset = {} if not nodes: nodes = mc.ls(sl=True) if not nodes: return if excludeChannels: if not isinstance(excludeChannels, (list, tuple)): excludeChannels = [excludeChannels] chans = None if selectedChannels: chans = mc.channelBox(gChannelBoxName, query=True, sma=True) l_trans = ['translateX','translateY','translateZ','rotateX','rotateY','rotateZ','scaleX','scaleY','scaleZ','tx','ty','yz','rx','ry','rz','sx','sy','sz'] for obj in nodes: #mObj = r9Meta.MetaClass(obj) attrs = chans if not chans: attrs = mc.listAttr(obj, keyable=True, unlocked=True) if excludeChannels: attrs = [x for x in attrs if x not in excludeChannels] if transformsOnly: attrs = [x for x in attrs if x in l_trans] if keyableOnly: attrs = [x for x in attrs if ATTR.is_keyable(obj,x)] d_defaults = {} for plug in ['defaultValues','transResets']: if ATTR.has_attr(obj, plug): d_defaults = getattr(r9Meta.MetaClass(obj),plug) if not attrs: log.warning("{0} resetAttrs | no attributes offered!".format(obj)) continue for a in attrs: try: if transformsOnly is not None and transformsOnly: if ATTR.get_nameLong(obj,a) not in l_trans: continue dVal = d_defaults.get(a) if dVal is not None: default = dVal else: default = mc.attributeQuery(a, listDefault=True, node=obj)[0] ATTR.set(obj,a,default) _reset[a] = default except Exception,err: log.error("{0}.{1} resetAttrs | error: {2}".format(obj, a,err))
def get_selectedFromChannelBox(attributesOnly=False): """ Returns a list of selected object attributes from the channel box :parameters: attributesOnly(bool): Whether you want Keyword arguments: returnRaw() -- whether you just want channels or objects combined with selected attributes """ _sel = mc.ls(sl=True) ChannelBoxName = mel.eval('$tmp = $gChannelBoxName') sma = mc.channelBox(ChannelBoxName, query=True, sma=True) ssa = mc.channelBox(ChannelBoxName, query=True, ssa=True) sha = mc.channelBox(ChannelBoxName, query=True, sha=True) soa = mc.channelBox(ChannelBoxName, query=True, soa=True) channels = [] if sma: channels.extend(sma) if ssa: channels.extend(ssa) if sha: channels.extend(sha) if soa: channels.extend(soa) if channels and _sel: _channels_long = [] for c in channels: _channels_long.append(ATTR.get_nameLong(_sel[0], c)) if attributesOnly: return _channels_long else: _res = [] for item in _sel: for attr in _channels_long: _res.append("{0}.{1}".format(item, attr)) return _res return False