def displayAllCurves(): ''' ''' # Display all attribute curves sel = mc.selectionConnection('graphEditorList', q=True, object=True) for obj in sel: mc.selectionConnection('graphEditor1FromOutliner', e=True, select=obj)
def createChannelBoxForNode(node): ''' This function pops open an independent channel box window in maya, for the node supplied in the arguments. ''' assert cmds.objExists(node), "Node %s does not exist!!!" % node selectionConnectionName = ("%s_rigBuilderSelectionConnection" % node) selectionConnection = None if cmds.selectionConnection(selectionConnectionName, ex=True): selectionConnection = selectionConnectionName else: selectionConnection = cmds.selectionConnection(selectionConnectionName) cmds.selectionConnection(selectionConnectionName, e=True, obj=node) channelBoxWindow = cmds.window(t=node) formLayout = cmds.formLayout(p=channelBoxWindow) channelBox = cmds.channelBox(p=formLayout, mlc=selectionConnection) cmds.formLayout(formLayout, e=True, af=[(channelBox, "top", 0), (channelBox, "bottom", 0), (channelBox, "left", 0), (channelBox, "right", 0)]) return cmds.showWindow(channelBoxWindow)
def getGraphSelection(panel='graphEditor1', useSelectedCurves=True): '''A robust method of finding the selected objects/attributes in the graph editor. If nothing is selected, all objects in the graph outliner will be returned. If a one or more curves are selected, those curves take precedence over any other selection. Always returns a list.''' # First see if there are any curves selected if useSelectedCurves: selection = getSelectedCurves() if selection: return selection else: selection = [] # Get the graph outliner ui name. outliner = getEditorFromPanel(panel, cmd.outlinerEditor) if outliner is not None: # Find selected attributes sc = cmd.outlinerEditor(outliner, q=1, selectionConnection=1) selection = cmd.selectionConnection(sc, q=1, object=1) # If nothing is selected, find objects present in outliner. if not selection: sc = cmd.outlinerEditor(outliner, q=1, mainListConnection=1) selection = cmd.selectionConnection(sc, q=1, object=1) if not selection: selection = [] return selection
def reset(): ''' adds the actually selected objects to selectionConnection ''' from maya.cmds import selectionConnection, ls selectionConnection('graphEditor1FromOutliner', e=1, clear=1) for s in ls(sl=1): selectionConnection('graphEditor1FromOutliner', e=1, object=s)
def isolate(option): sel = mc.ls(sl=True) if not sel: return graphVis = mc.selectionConnection('graphEditor1FromOutliner', query=True, obj=True) channels = list() wildCard = str() alreadyIsolated = True if graphVis: for c in graphVis: if not '.' in c and mc.objExists(c): attrs = mc.listAttr(c, keyable=True, unlocked=True) if attrs: channels.extend([c+'.'+a for a in attrs]) else: attr = c.split('.')[-1] if attr.startswith(option): channels.append(c) if not wildCard: wildCard = option+'*' elif attr.endswith(option): channels.append(c) if not wildCard: wildCard = '*'+option elif attr == option: channels.append(c) if not wildCard: wildCard = option else: #found a curve that is outside our search parameters alreadyIsolated = False if channels and alreadyIsolated: #if the option is already the only thing being displayed, then show everything that matches the option for obj in sel: attrs = mc.listAttr(obj, keyable=True, unlocked=True, string=wildCard) if attrs: channels.extend([obj+'.'+a for a in attrs]) if not channels: for obj in sel: attrs = mc.listAttr(obj, keyable=True, unlocked=True) for a in attrs: if a==option or a.startswith(option) or a.endswith(option): channels.append(obj+'.'+a) clear() for c in channels: mc.selectionConnection('graphEditor1FromOutliner', edit=True, select=c)
def graphSelectedCurves( self ): curves = cmds.keyframe( q=True, name=True, sl=True ) if not curves: return self.clearSelection() for curve in curves: channel = cmds.listConnections( '%s.output' % curve, p=True, s=False ) if cmds.objExists( channel[0] ): cmds.selectionConnection( self._selectedSC, e=True, select=channel[0] )
def selected(*args): curves = mc.keyframe(query=True, selected=True, name=True) if not curves: return clear() for c in curves: plug = mc.listConnections(c, plugs=True, source=False, destination=True) mc.selectionConnection('graphEditor1FromOutliner', edit=True, select=plug[0])
def updateOutliner(self): inputList = cmds.selectionConnection(worldList=True) fromEditor = cmds.selectionConnection(activeList=True) CBcurrText = self.filtersCB.currentText() filterItem = cmds.itemFilter(byType = str(CBcurrText)) cmds.outlinerEditor(self.outlinerName, edit=True, mainListConnection=inputList, filter=filterItem) cmds.outlinerEditor(self.outlinerName, edit=True, selectionConnection=fromEditor)
def channelbox_command_animCurve(box, menuItem, key, *args): with sysCmd.Undo(0): mel.eval("GraphEditor;") cmds.selectionConnection("graphEditor1FromOutliner", e=1, clear=1) # in case graph editor is open already, clear selection sel_attrs = channelBox_SelectedPlugs(box) if sel_attrs: for i in sel_attrs: cmds.evalDeferred( "cmds.selectionConnection('graphEditor1FromOutliner', e = 1, select =\"" + i + "\")")
def showAll(*args): sel = mc.ls(sl=True) if not sel: return for each in sel: attrs = mc.listAttr(each, keyable=True, unlocked=True) if attrs: for a in attrs: mc.selectionConnection('graphEditor1FromOutliner', edit=True, select=each+'.'+a)
def addCurveToEditor(attr): ''' ''' # Get current selection sel = mc.ls(sl=True) for obj in sel: objAttr = obj+'.'+attr # Check attr if mc.objExists(objAttr): # Add to graphEditor mc.selectionConnection('graphEditor1FromOutliner',e=True,select=objAttr)
def channelBox(*args): channels = utl.getSelectedChannels() if not channels: return sel = mc.ls(sl=True) clear() for each in sel: for c in channels: if mc.attributeQuery(c, node=each, exists=True): mc.selectionConnection('graphEditor1FromOutliner', edit=True, select=each+'.'+c)
def graphNamedChannels( self, channels ): ''' graphs the named channels on all selected objects should the channel exist EXAMPLE: self.graphNamedChannels( ['tx', 'ty', 'tz'] ) ''' self.clearSelection() for node in self.getDisplayedNodes(): for channel in channels: channelPath = '%s.%s' % (node, channel) if cmds.objExists( channelPath ): cmds.selectionConnection( self._selectedSC, e=True, select=channelPath )
def showAll(*args): sel = mc.ls(sl=True) if not sel: return for each in sel: attrs = mc.listAttr(each, keyable=True, unlocked=True) if attrs: for a in attrs: mc.selectionConnection('graphEditor1FromOutliner', edit=True, select=each + '.' + a)
def graphFilter(): sels = mc.ls(sl=1) if len(sels): mlc = mc.animCurveEditor('graphEditor1GraphEd', q=1, mlc=1) selectedAttrs = mc.selectionConnection(mlc, q=1, obj=1) attrs = [] for selectedAttr in selectedAttrs: attrs.append(selectedAttr.split('.')[1]) mc.selectionConnection(mlc, e=1, cl=1) for sel in sels: for attr in set(attrs): mc.selectionConnection(mlc, e=1, s=(sel+'.'+attr))
def clearGraphEditor(panel): '''Deselects the attributes of the specified graphEditor panel by clearing the selectionConnection.''' selectionConnection = selectedAttributes.selectionConnectionFromPanel(panel) # Clear current selection, including filtered attributes cmd.selectionConnection(selectionConnection, e=1, clr=1) # Reselect just the nodes. Restoring the graph editor to the state # it would be in if you had just selected these. for node in cmd.ls(selection=True): cmd.selectionConnection(selectionConnection, edit=True, select=node)
def isolate(): ''' clears and adds only selected curves to selectionConnection ''' from maya.cmds import selectionConnection, keyframe, listConnections kSel = keyframe(q=1, sl=1, name=1) if not kSel: return selectionConnection('graphEditor1FromOutliner', e=1, clear=1) plugs = listConnections(kSel, p=1) for p in plugs: selectionConnection('graphEditor1FromOutliner', e=1, object=p)
def addCurveToEditor(attr): """ """ # Get current selection sel = cmds.ls(sl=True) for obj in sel: objAttr = obj + '.' + attr # Check attr if cmds.objExists(objAttr): # Add to graphEditor cmds.selectionConnection('graphEditor1FromOutliner', e=True, select=objAttr)
def graphNamedChannels(self, channels): ''' graphs the named channels on all selected objects should the channel exist EXAMPLE: self.graphNamedChannels( ['tx', 'ty', 'tz'] ) ''' self.clearSelection() for node in self.getDisplayedNodes(): for channel in channels: channelPath = '%s.%s' % (node, channel) if cmds.objExists(channelPath): cmds.selectionConnection(self._selectedSC, e=True, select=channelPath)
def getGraphEditor(graphInfo, expandObjects=True, useSelectedCurves=True, animatableOnly=True, usePartialCurveSelection=True): ''' Get attributes selected in the graph editor. If expandObjects is true, attributes are saved in the format object.attribute and a lack of selection or an entire object selected will expand to that object's keyable nodes. Otherwise, the list will be a mix of object.attribute and object. Objects will not have their attributes expanded. ''' selection = [] # Check for curves first, we may use those exclusively if useSelectedCurves: selection = getSelectedCurves( usePartialCurveSelection=usePartialCurveSelection) if selection: return selection # Get the graph outliner ui name. outliner = getEditorFromPanel(graphInfo.panelName, cmd.outlinerEditor) if outliner is not None: # Find attributes selected in the graph editor's outliner sc = cmd.outlinerEditor(outliner, q=1, selectionConnection=1) selection = cmd.selectionConnection(sc, q=1, object=1) # If nothing is selected, find objects present in outliner. if not selection: sc = cmd.outlinerEditor(outliner, q=1, mainListConnection=1) selection = cmd.selectionConnection(sc, q=1, object=1) if not selection: selection = [] attributes = [] if selection: # This is rare, but eliminate underworld paths. removeUnderworldFromPath(selection) attributes = filterSelectedToAttributes(selection, expandObjects, animatableOnly) return attributes
def graphSelectedCurves(self): curves = cmds.keyframe(q=True, name=True, sl=True) if not curves: return self.clearSelection() for curve in curves: channel = cmds.listConnections('%s.output' % curve, p=True, s=False) if cmds.objExists(channel[0]): cmds.selectionConnection(self._selectedSC, e=True, select=channel[0])
def channelBox(*args): channels = utl.getSelectedChannels() if not channels: return sel = mc.ls(sl=True) clear() for each in sel: for c in channels: if mc.attributeQuery(c, node=each, exists=True): mc.selectionConnection('graphEditor1FromOutliner', edit=True, select=each + '.' + c)
def highlightAttrs(attrs=[]): """ Syncs all the selected attributes of the loaded nodes in the graph editor If the attr flag is passed, only that attribute would get synced, otherwise the selected attributes will be used """ loaded = getLoaded() ## If there is nothing loaded in GE, dont do anything if not len(loaded): MC.warning("There is nothing loaded in graph editor") return ## Figure out the selected attrs if there isn't one passed in if not len(attrs): allselected = getSelected() if allselected == []: msg = ("There is no attribute selected in graph editor, nor " + " one passed as an argument. Can't sync selection") MC.warning(msg) return attrs = [] for alls in allselected: toks = alls.split(".") if len(toks) < 2: continue # Skip highlighted nodes attrs.append(toks[1]) attrs = list(set(attrs)) ## If there are no attrs, then nothing to highlight if not len(attrs): MC.warning("There are no attrs to highlight") return ## Loop through loaded nodes, and highglight its attrs tohighlight = [] for load in loaded: for attr in attrs: tohighlight.append(load + "." + attr) ## Load the new selection for x in tohighlight: MC.selectionConnection(GE_SELCON, select=x, e=1) print "Synced Highlighted Attributes"
def graphFilterScale(): sels = mc.ls(sl=1) mlc = mc.animCurveEditor('graphEditor1GraphEd', q=1, mlc=1) mc.selectionConnection(mlc, e=1, clear=1) for sel in sels: mc.selectionConnection(mlc, e=1, s=(sel+'.scaleX')) mc.selectionConnection(mlc, e=1, s=(sel+'.scaleY')) mc.selectionConnection(mlc, e=1, s=(sel+'.scaleZ'))
def syncGraphEditor(): """Syncs the attributes selected in the channelBox to those in the graphEditor. I don't know of any way to select channelBox attributes, so I have not been able to implement the equivalent syncChannelBox.""" # Get channelbox attributes attributes = selectedAttributes.getChannelBox(expandObjects=False) # Clear graph editor attributes selectionConnection = selectedAttributes.getSelectionConnection() cmd.selectionConnection(selectionConnection, e=1, clr=1) # Select channelbox attributes in graph editor for attr in attributes: cmd.selectionConnection(selectionConnection, edit=True, select=attr)
def tangentScale(value, outValue=None): if outValue == None: outValue = value curves = None #order of operations: #selected keys, visible in graph editor on current frame selected = False time = mc.currentTime(query=True) curves = mc.keyframe(query=True, name=True, selected=True) if curves: #try selected keys first selected = True else: #then visible in graph editor graphVis = mc.selectionConnection('graphEditor1FromOutliner', query=True, obj=True) if graphVis: curves = mc.keyframe(graphVis, query=True, name=True) else: #otherwise try keyed channels. sel = mc.ls(sl=True) if not sel: return curves = mc.listConnections(sel, s=True, d=False, type='animCurve') if not curves: return for curve in curves: keyTimes = list() #set tangents weighted if they aren't already if mc.keyTangent(curve, query=True, weightedTangents=True): mc.keyTangent(curve, edit=True, weightedTangents=True) if selected: keyTimes = mc.keyframe(curve, query=True, timeChange=True, selected=True) else: keyTimes = [time] for t in keyTimes: weight = mc.keyTangent(curve, time=(t,), query=True, inWeight=True, outWeight=True) if not weight: continue inOut = list() for w,v in zip(weight,[value,outValue]): if v<1 and w < 0.1: inOut.append(0) elif v>1 and w == 0: inOut.append(0.1) else: inOut.append(w*v) mc.keyTangent(curve, time=(t,), edit=True, absolute=True, inWeight=inOut[0], outWeight=inOut[1])
def filterNonAnimatedCurves(): curvesShown = cmds.animCurveEditor( 'graphEditor1GraphEd', query=True, curvesShown=True) if curvesShown: objsAttrs = getTarget("", curvesShown) cmds.selectionConnection( 'graphEditor1FromOutliner', e=True, clear=True) cmds.waitCursor(state=True) for n, loopCurve in enumerate(curvesShown): keyValues = cmds.keyframe(loopCurve, query=True, valueChange=True) if max(keyValues) != min(keyValues): cmds.selectionConnection('graphEditor1FromOutliner', edit=True, select="%s.%s"%(objsAttrs[0][n], objsAttrs[1][n])) #framePlaybackRange.framePlaybackRangeFn() cmds.waitCursor(state=False)
def ui_onOutlinerSelectSG(self, sc): if self.state.currentView.selectSetMembers: SGs = m.selectionConnection(sc, q=True, object=True) if not SGs: return assignedTo = m.sets(SGs, q=True) if assignedTo: m.select(assignedTo)
def filterCurves(): ''' ''' # Check attribute list selection if mc.textScrollList('graphFilter_attrListTSL',q=True,nsi=True): # Check mode if mc.radioButtonGrp('graphFilter_modeRBG',q=True,sl=True) == 1: mc.selectionConnection('graphEditor1FromOutliner',e=True,clear=True) attrs = mc.textScrollList('graphFilter_attrListTSL',q=True,si=True) for attr in attrs: addCurveToEditor(attr) # Update UI mm.eval('GraphEditor') mm.eval('SelectAllMarkingMenu') mm.eval('buildSelectAllMM') mm.eval('SelectAllMarkingMenuPopDown')
def isolate(option): sel = mc.ls(sl=True) if not sel: return graphVis = mc.selectionConnection('graphEditor1FromOutliner', query=True, obj=True) channels = list() wildCard = str() alreadyIsolated = True if graphVis: for c in graphVis: if not '.' in c and mc.objExists(c): attrs = mc.listAttr(c, keyable=True, unlocked=True) if attrs: channels.extend(attrs) else: attr = c.split('.')[-1] if attr.startswith(option): channels.append(attr) if not wildCard: wildCard = option + '*' elif attr.endswith(option): channels.append(attr) if not wildCard: wildCard = '*' + option elif attr == option: channels.append(attr) if not wildCard: wildCard = option else: #found a curve that is outside our search parameters alreadyIsolated = False if channels and alreadyIsolated: #if the option is already the only thing being displayed, then show everything that matches the option for obj in sel: attrs = mc.listAttr(obj, keyable=True, unlocked=True, string=wildCard) if attrs: channels.extend(attrs) if not channels: for obj in sel: attrs = mc.listAttr(obj, keyable=True, unlocked=True) if attrs: channels = [ a for a in attrs if a == option or a.startswith(option) or a.endswith(option) ] filterChannels(channels)
def spreadSheetUI(*args): if cmds.window("sheetID", exists=True): cmds.deleteUI('sheetID') sheetID = cmds.window("sheetID", t="Spread Sheet Editor", widthHeight=(400, 300)) cmds.paneLayout() activeList = cmds.selectionConnection(activeList=True) cmds.spreadSheetEditor(mainListConnection=activeList) cmds.showWindow(sheetID)
def filterNonAnimatedCurves(): curvesShown = cmds.animCurveEditor("graphEditor1GraphEd", query=True, curvesShown=True) if curvesShown: objsAttrs = getTarget("", curvesShown) cmds.selectionConnection("graphEditor1FromOutliner", e=True, clear=True) cmds.waitCursor(state=True) for n, loopCurve in enumerate(curvesShown): keyValues = cmds.keyframe(loopCurve, query=True, valueChange=True) if max(keyValues) != min(keyValues): cmds.selectionConnection( "graphEditor1FromOutliner", edit=True, select="%s.%s" % (objsAttrs[0][n], objsAttrs[1][n]) ) # framePlaybackRange.framePlaybackRangeFn() cmds.waitCursor(state=False)
def areChannelsHighlighted(self): ''' returns whether the highlighted channels in the graph editor are attributes or not ''' sel = cmds.selectionConnection(self._selectedSC, q=True, obj=True) for s in sel: if '.' in s: return True return False
def areChannelsHighlighted( self ): ''' returns whether the highlighted channels in the graph editor are attributes or not ''' sel = cmds.selectionConnection( self._selectedSC, q=True, obj=True ) for s in sel: if '.' in s: return True return False
def ui_onOutlinerSelectMatTex(self, sc): if self.state.currentView.selectSetMembers: selected = m.selectionConnection(sc, q=True, object=True) if not selected: return SGs = self.getSGs(selected) if not SGs: return assignedTo = m.sets(SGs, q=True) if assignedTo: m.select(assignedTo)
def syncGraphEditor(graphInfo=None): ''' Syncs the attributes selected in the channelBox to those in the graphEditor. ''' graphInfo = graphInfo or selectedAttributes.GraphEditorInfo.detect() if not graphInfo.isValid(): return # Get channelbox attributes attributes = selectedAttributes.getChannelBox(expandObjects=False) # Clear graph editor attributes selectionConnection = selectedAttributes.selectionConnectionFromPanel( graphInfo.panelName) cmd.selectionConnection(selectionConnection, e=1, clr=1) # Select channelbox attributes in graph editor for attr in attributes: cmd.selectionConnection(selectionConnection, edit=True, select=attr)
def filterCurves(): """ """ # Check attribute list selection if cmds.textScrollList('graphFilter_attrListTSL', q=True, nsi=True): # Check mode if cmds.radioButtonGrp('graphFilter_modeRBG', q=True, sl=True) == 1: cmds.selectionConnection('graphEditor1FromOutliner', e=True, clear=True) attrs = cmds.textScrollList('graphFilter_attrListTSL', q=True, si=True) for attr in attrs: addCurveToEditor(attr) # Update UI mel.eval('GraphEditor') mel.eval('SelectAllMarkingMenu') mel.eval('buildSelectAllMM') mel.eval('SelectAllMarkingMenuPopDown')
def currentSet2(): ge = 'graphEditor1OutlineEd' sel = cmds.ls(sl=1) cmds.select(cl=1) # shows selectionConnection object, populates ge geL = cmds.outlinerEditor(ge, q=1, mlc=1) # active sets result = cmds.selectionConnection(geL, q=1, obj=1) if sel: cmds.select(sel) return result
def spreadSheetWin(self): if mel.window('autoProSpreadSheetWindow', exists=1): mel.deleteUI('autoProSpreadSheetWindow', window=1) window = mel.window('autoProSpreadSheetWindow', title="autoPro SpreadSheet", iconName="autoProSprSht", widthHeight=(400, 300)) mel.paneLayout() activeList = mel.selectionConnection(activeList=True) mel.spreadSheetEditor(mainListConnection=activeList) mel.showWindow('autoProSpreadSheetWindow')
def isIsolated(): ''' looks for an attribute entry or animCurves in object list of selectionConnection if so the view is considered as 'isolated' ''' from maya.cmds import selectionConnection, ls from fnmatch import fnmatch displayed = selectionConnection('graphEditor1FromOutliner', q=1, object=1) if ls(displayed, type='animCurve'): return True for d in displayed: if fnmatch(d, '*.*'): return True return False
def GreenTickKeys(iAllFrame=0): oKeyPoseFrames = 'KeyPoseFrames' aKeyFrames = [] if cmds.objExists(oKeyPoseFrames): for i in range(cmds.keyframe(oKeyPoseFrames + '.tx', kc=True, q=True)): aKeyFrames.extend( cmds.keyframe(oKeyPoseFrames + '.tx', index=(i, i), q=True)) aObjList = [ str(s) for s in cmds.selectionConnection( 'graphEditor1FromOutliner', q=True, object=True) or [] ] #aCurveList = [str(s) for s in cmds.keyframe(q = True, name = True)] # Store Selected Keys aSelection = [] for o in aObjList: aName = cmds.keyframe(o, query=True, name=True) aKeys = cmds.keyframe(o, sl=True, q=True) if aName and aKeys: aSelection.append([str(aName[0]), aKeys]) if cmds.ls(sl=True): cmds.selectKey(clear=True) # DO fTime = cmds.currentTime(q=True) if fTime in aKeyFrames: cmds.keyframe(t=(fTime, fTime), tds=True) # Select Stored keys if aSelection: for a in aSelection: sName = a[0] for t in a[1]: cmds.selectKey(sName, t=(t, t), tgl=True) # Update All Frames red/green. if iAllFrame: iIn = int(cmds.playbackOptions(q=True, minTime=True)) iOut = int(cmds.playbackOptions(q=True, maxTime=True)) for i in range(iIn, iOut + 1): if i in aKeyFrames: cmds.keyframe(t=(i, i), tds=True) else: cmds.keyframe(t=(i, i), tds=False)
def func( *args, **kwargs ): modelPanels = cmd.getPanel( vis=True ) emptySelConn = cmd.selectionConnection() for panel in modelPanels: if cmd.getPanel( to=panel ) == 'modelPanel': cmd.isolateSelect( panel, state=True ) cmd.modelEditor( panel, e=True, mlc=emptySelConn ) try: return f( *args, **kwargs ) finally: for panel in modelPanels: if cmd.getPanel( to=panel ) == 'modelPanel': cmd.isolateSelect( panel, state=False ) cmd.deleteUI( emptySelConn )
def func(*args, **kwargs): modelPanels = cmd.getPanel(vis=True) emptySelConn = cmd.selectionConnection() for panel in modelPanels: if cmd.getPanel(to=panel) == 'modelPanel': cmd.isolateSelect(panel, state=True) cmd.modelEditor(panel, e=True, mlc=emptySelConn) try: ret = f(*args, **kwargs) except: raise finally: cmd.deleteUI(emptySelConn) return ret
def showShapesDisplacementSheet(self): shaderSelected = edCore.edToolsShadingSelectedAI if shaderSelected: shapes = edCore.getters.getShapesByMaterial(shaderSelected) cmds.select(shapes, visible=True) #Show Window window = cmds.window(shaderSelected, widthHeight=(1000, 800)) cmds.paneLayout() activeList = cmds.selectionConnection(activeList=True) cmds.spreadSheetEditor(mainListConnection=activeList, selectedAttr=True, keyableOnly=False, fixedAttrList=[ 'aiSubdivType', 'aiDispHeight', 'aiSubdivIterations', 'aiDispAutobump', 'customDisplacement' ]) cmds.showWindow(window)
def selectSimilarAttributes(detectCursor=True): """Selects the same attributes already selected on every node in the Graph Editor. When detectCursor is true, if your cursor is not over the Graph Editor, the Channel Box attributes are synced to the Graph Editor using the method syncGraphEditor(). """ # Where is the cursor? useGraphEditor, panel = selectedAttributes.isGraphEditorActive() # Select similar attributes. if useGraphEditor or not detectCursor: # Get selected nodes and attributes attributes = selectedAttributes.getGraphEditor(panel, expandObjects=False) nodes = cmd.ls(sl=1, l=1) # Clear graph editor attributes selectionConnection = selectedAttributes.getSelectionConnection(panel) cmd.selectionConnection(selectionConnection, e=1, clr=1) # Process attributes # Get the attribute part of node.attribute and separate out # selected objects. objs = [] for x in reversed(range(len(attributes))): if "." in attributes[x]: # This works for compound attributes too. Trust me. null, attributes[x] = selectedAttributes.splitAttr(attributes[x]) else: objs.append(attributes.pop(x)) attributes = list(set(attributes)) # Select the attributes on every node selected for attr in attributes: for node in nodes: try: cmd.selectionConnection(selectionConnection, edit=True, select="%s.%s" % (node, attr)) except RuntimeError: # That attribute probably didn't exist on that node. pass # reselect objects for obj in objs: cmd.selectionConnection(selectionConnection, edit=True, select=obj) else: syncGraphEditor()
def ge_update(): pm.selectionConnection("graphEditor1FromOutliner", e=True, clear=True) for c in cnxs: cmds.selectionConnection("graphEditor1FromOutliner", e=True, select=c)
def __init__(self, selectionOrder): allArgOptions = [ 'selectedObjects', 'selectedChannels', 'inGraphEditor', 'selectedKey', 'selectedCurve', 'keyedChannels', 'selectedNamespace', 'scene', 'setKey', 'range', 'toEnd', 'fromBeginning', 'timeSlider', 'selectedKeyRange', 'previous', 'next', 'current', 'includeShapes' ] if not isinstance(selectionOrder, list) and not isinstance(selectionOrder, tuple): OpenMaya.MGlobal.displayWarning('selectionOrder argument should be a list of lists.') return for each in selectionOrder: if not isinstance(each, list) and not isinstance(each, tuple): OpenMaya.MGlobal.displayWarning('Each element in the selectionOrder argument should also be a list.') shortestTime = getFrameRate()/6000 self.curves = list() self.channels = list() self.args = dict() sel = mc.ls(sl=True) currentTime = mc.currentTime(query=True) time = currentTime self.time = None self.timeStart = None self.timeEnd = None self.timeRange = None self.selected = False #Is the graph editor open? graphEdExists = False if 'graphEditor1' in mc.getPanel(visiblePanels=True): graphEdExists = True #declare variable for the arg loop animNode = list() for arg in selectionOrder: holdChannels = list() if 'selectedObjects' in arg: #This argument acts on selected objects if not sel: continue if 'setKey' in arg: for obj in sel: keyable = mc.listAttr(obj, keyable=True, unlocked=True) for attr in keyable: plug = '.'.join((obj, attr)) if mc.listConnections(plug, s=True, d=False, type='animCurve') or not mc.listConnections(plug, s=True, d=False): holdChannels.append(plug) elif mc.listConnections(plug, s=True, d=False, type='animBlendNodeAdditiveDL'): OpenMaya.MGlobal.displayWarning('Warning, this might not work. channels are connected to an animBlend node') holdChannels.append(plug) else: holdChannels = sel elif 'selectedChannels' in arg: chanBoxChan = getSelectedChannels() if not chanBoxChan: continue for obj in sel: for attr in chanBoxChan: if mc.attributeQuery(attr, node=obj, exists=True): holdChannels.append('.'.join((obj,attr))) elif 'inGraphEditor' in arg: if not graphEdExists: continue graphVis = mc.selectionConnection('graphEditor1FromOutliner', query=True, obj=True) if not graphVis: continue for each in graphVis: if 'setKey' in arg: chan = getChannelFromAnimCurve(each) if chan: holdChannels.append(chan) else: holdChannels.append(each) else: try: holdChannels.extend(mc.keyframe(each, query=True, name=True)) except StandardError: pass elif 'selectedKey' in arg or 'selectedCurve' in arg: if not graphEdExists: continue animNode = mc.keyframe(query=True, name=True, selected=True) if not animNode: continue if 'setKey' in arg: for each in animNode: holdChannels.append(getChannelFromAnimCurve(each)) else: self.selected = True holdChannels.extend(animNode) #need a way to store times here? keyTimes = mc.keyframe(animNode, query=True, timeChange=True, selected=True) self.time = keyTimes keyTimes.sort() self.timeStart = keyTimes[0] self.timeEnd = keyTimes[-1] elif 'keyedChannels' in arg: if not sel: continue objs = sel if 'includeShapes' in arg: shapes = mc.listRelatives(sel, shapes=True) if shapes: objs.extend(shapes) #this should skip driven keys tl = mc.listConnections(objs, s=True, d=False, type='animCurveTL') ta = mc.listConnections(objs, s=True, d=False, type='animCurveTA') tu = mc.listConnections(objs, s=True, d=False, type='animCurveTU') if tl: animNode.extend(tl) if ta: animNode.extend(ta) if tu: animNode.extend(tu) if not animNode: continue holdChannels.extend(animNode) elif 'selectedNamespace' in arg: pass elif 'scene' in arg: animNode = mc.ls(type='animCurveTL') animNode.extend(mc.ls(type='animCurveTA')) animNode.extend(mc.ls(type='animCurveTU')) if not animNode: continue if 'setKey' in arg: for each in animNode: holdChannels.append(getChannelFromAnimCurve(each)) else: holdChannels.extend(animNode) else: argNotFound = False for each in arg: if not each in allArgOptions: OpenMaya.MGlobal.displayWarning('Argument not recognized: '+each) argNotFound = True if argNotFound: print '\nLegal arguments:' for each in allArgOptions: print '\t'+each print '' OpenMaya.MGlobal.displayWarning('One or more arguments not recognized, see script editor for argument list.') return continue #if no channels, continue on to the next iteration if not holdChannels: continue self.channels = holdChannels if 'setKey' in arg: #this is a special arg, which creates keys on the attributes determined so far self.setKeyframe(insert=True) #not sure that this should be managed in KeySelection # if 'deleteSubFrames' in arg: # #remove nearby sub-frames # #this breaks at higher frame ranges because maya doesn't keep enough digits # #this value is also different for different frame rates # time = mc.currentTime(query=True) # if time % 1 == 0 and -9999 < time < 9999: # #the distance that keys can be is independent of frame rate, so we have to convert based on the frame rate. # tol = getFrameRate()/6000.0 # mc.cutKey(holdChannels, time=(time+tol,time+0.5)) # mc.cutKey(holdChannels, time=(time-0.5,time-tol)) #self.flags['time'] = time self.time=(time,) #check that none of the animation curves are referenced and therefor uneditable #supposedly these are editable in 2013, so may have to update after I can test it. #in the future, it might be nice to have this culling happen before keys are set and cut. animCurves = mc.keyframe(self.channels, query=True, name=True) if animCurves: for curve in animCurves: if mc.referenceQuery(curve, isNodeReferenced=True): animCurves.remove(curve) #need to determine when it's ok to continue working on channels without curves if not animCurves and not 'selectedChannels' in arg and not 'selectedObjects' in arg: continue self.curves = animCurves if 'range' in arg: #this is selected range in the time slider self.timeStart, self.timeEnd = frameRange() break elif 'toEnd' in arg: if not 'current' in arg: time+=shortestTime self.time = (str(time)+':',) self.timeStart = time break elif 'fromBeginning' in arg: if not 'current' in arg: time-=shortestTime self.time = (':'+str(time),) self.timeEnd = time break elif 'selectedKeyRange' in arg: keyTimes = mc.keyframe(self.curves, query=True, timeChange=True, selected=True) if not keyTimes: continue keyTimes.sort() if keyTimes[0] == keyTimes[-1]: continue self.time = (keyTimes[0],keyTimes[-1]) self.timeStart = keyTimes[0] self.timeEnd = keyTimes[-1] break else: if 'current' in arg: self.time = (currentTime,) if 'previous' in arg: frame = mc.findKeyframe(self.curves, time=(time,), which='previous') self.timeStart = frame if self.time: self.time.append(self.timeStart) else: self.time = (self.timeStart,) if 'next' in arg: frame = mc.findKeyframe(self.curves, time=(time,), which='next') self.timeEnd = frame if self.time: self.time.append(self.timeEnd) else: self.time = (self.timeEnd,) #finally, if no range arguments have been used, return all keys on the curve if not self.time: self.time = (':',) break
def getSelected(self): return cmds.selectionConnection(self._selectedSC, q=True, obj=True) or []
def holdRange(current=False, average=False): ''' Create a hold over a range of frames. Arguments: current: hold value comes from current frame average: hold value comes from the average of all keys over the range. ''' if (current and average) or (not current and not average): OpenMaya.MGlobal.displayWarning( 'This function requires exactly one argument to be true.') return sel = mc.ls(sl=True) if not sel: OpenMaya.MGlobal.displayWarning('Nothing selected.') return curves = None start = None end = None value = None currentTime = mc.currentTime(query=True) graphVis = mc.selectionConnection('graphEditor1FromOutliner', query=True, obj=True) # first check if a range is selected gPlayBackSlider = mm.eval('$temp=$gPlayBackSlider') if mc.timeControl(gPlayBackSlider, query=True, rangeVisible=True): pbRange = mc.timeControl(gPlayBackSlider, query=True, rangeArray=True) start = float(pbRange[0]) end = float(pbRange[1]) - 1 #visible in graph editor if graphVis: curves = mc.keyframe(graphVis, query=True, name=True) else: curves = mc.keyframe(sel, query=True, name=True) else: #selected key range curves = mc.keyframe(query=True, name=True, selected=True) if curves: keyTimes = mc.keyframe(query=True, timeChange=True, selected=True) keyTimes.sort() if keyTimes[0] == keyTimes[-1]: return start = keyTimes[0] end = keyTimes[-1] else: if graphVis: curves = mc.keyframe(graphVis, query=True, name=True) else: curves = mc.keyframe(sel, query=True, name=True) start = mc.findKeyframe(curves, time=(currentTime, ), which='previous') end = mc.findKeyframe(curves, time=(currentTime, ), which='next') #set start and end frames mc.setKeyframe(curves, time=(start, end)) #if you're using maya before 2011, python doesn't undo properly with utl.UndoChunk(): for curve in curves: if average: v = mc.keyframe(curve, time=(start, end), query=True, valueChange=True) value = sum(v) / len(v) elif current: if 'animCurveT' in mc.nodeType(curve): plug = mc.listConnections('.'.join((curve, 'output')), source=False, plugs=True)[0] value = mc.getAttr(plug) mc.keyframe(curve, time=(start, end), edit=True, valueChange=value) #delete inbetweens if (end - start) > 1: mc.cutKey(curves, time=(start + 0.1, end - 0.1)) itt, ott = utl.getHoldTangentType() mc.keyTangent(curves, time=(start, end), itt=itt, ott=ott)
def syncChannelBox(graphInfo=None, perfectSync=False, useSelectedCurves=True, usePartialCurveSelection=True): ''' Syncs the attributes selected in the graphEditor to those in the channelBox. Attributes selected in the graphEditor will be modified to so that every node has the same attributes selected - this "trues" up the channelbox selection with the graph editor. ''' graphInfo = graphInfo or selectedAttributes.GraphEditorInfo.detect() if not graphInfo.isValid(): return # Get selected nodes and attributes selected = selectedAttributes.getGraphEditor( graphInfo, expandObjects=False, useSelectedCurves=useSelectedCurves, usePartialCurveSelection=usePartialCurveSelection) nodes = cmd.ls(sl=1, l=1) # Process attributes # Get the attribute part of node.attribute and separate out # selected objects. objs = [] attributes = set() for nodeOrAttr in selected: if '.' in nodeOrAttr: # This works for compound attributes too. Trust me. attributes.add(selectedAttributes.splitAttr(nodeOrAttr)[1]) else: objs.append(nodeOrAttr) attributes = list(attributes) objAttrs = ["%s.%s" % (node, attr) for attr in attributes for node in nodes] try: # I hear that the select flag was added in Maya 2016 Extension 2 pm.channelBox( pm.melGlobals['gChannelBoxName'], select=objAttrs, edit=True) except TypeError: # Legacy behavior before channelBox -select flag was created # Does not actually sync with channel box, because that was impossible. # instead it just selected the same attributes on all graph nodes. if perfectSync: # Clear graph editor attributes selectionConnection = selectedAttributes.selectionConnectionFromPanel( graphInfo.panelName) cmd.selectionConnection(selectionConnection, edit=True, clr=True) # Select the attributes on every node selected for attr in attributes: for node in nodes: try: cmd.selectionConnection(selectionConnection, edit=True, select='%s.%s' % (node, attr)) except RuntimeError: # That attribute probably didn't exist on that node. pass # reselect objects for obj in objs: cmd.selectionConnection(selectionConnection, edit=True, select=obj) else: if perfectSync: syncGraphEditor(graphInfo=graphInfo)
def __init__(self, name='mlBreakdownDraggerContext', minValue=None, maxValue=None, defaultValue=0, title = 'Breakdown'): sel = mc.ls(sl=True) if not sel: return Dragger.__init__(self, defaultValue=defaultValue, minValue=minValue, maxValue=maxValue, name=name, title=title) selected = False time = mc.currentTime(query=True) curves = mc.keyframe(query=True, name=True, selected=True) if curves: #try selected keys first selected = True else: #then visible in graph editor graphVis = mc.selectionConnection('graphEditor1FromOutliner', query=True, obj=True) if graphVis: curves = mc.keyframe(graphVis, query=True, name=True) else: #otherwise try keyed channels. curves = mc.listConnections(sel, s=True, d=False, type='animCurve') if not curves: return #cull unkeyable curves remove = list() for c in curves: if mc.referenceQuery(c, isNodeReferenced=True): remove.append(c) else: plug = mc.listConnections('.'.join((c,'output')), source=False, plugs=True)[0] if not mc.getAttr(plug, keyable=True) and not mc.getAttr(plug, settable=True): remove.append(c) if remove: for r in remove: curves.remove(r) if not curves: return if not selected: mc.setKeyframe(curves) itt = 'plateau' ott = 'plateau' if mc.keyTangent(query=True, g=True, ott=True)[0]=='linear': itt='linear' ott='linear' elif mc.keyTangent(query=True, g=True, ott=True)[0]=='step': itt='linear' ott='step' self.curves = curves self.time = dict() self.value = dict() self.next = dict() self.prev = dict() self.average = dict() for curve in self.curves: if selected: self.time[curve] = mc.keyframe(curve, query=True, timeChange=True, sl=True) self.value[curve] = mc.keyframe(curve, query=True, valueChange=True, sl=True) else: self.time[curve] = [time] self.value[curve] = mc.keyframe(curve, time=(time,), query=True, valueChange=True) self.next[curve] = list() self.prev[curve] = list() self.average[curve] = list() for i in self.time[curve]: next = mc.findKeyframe(curve, time=(i,), which='next') prev = mc.findKeyframe(curve, time=(i,), which='previous') n = mc.keyframe(curve, time=(next,), query=True, valueChange=True)[0] p = mc.keyframe(curve, time=(prev,), query=True, valueChange=True)[0] self.next[curve].append(n) self.prev[curve].append(p) self.average[curve].append((n+p)/2) #set the tangents on this key, and the next and previous, so they flatten properly #if not mc.keyTangent(query=True, g=True, ott=True)[0]=='linear' and not mc.keyTangent(query=True, g=True, ott=True)[0]=='step': mc.keyTangent(curve, time=(i,), itt=itt, ott=ott) mc.keyTangent(curve, time=(next,), itt=itt) mc.keyTangent(curve, time=(prev,), ott=ott) self.setTool() self.drawString('Left: Weight Prev/Next, Middle: Weight Average') mm.eval('warning "Left: Weight Prev/Next, Middle: Weight Average"')
def deleteKey(deleteSubFrames=False, selectedKeys=False, selectedChannels=False, visibleInGraphEditor=False, currentFrame=False): ''' The main function arguments: selectedKeys: Delete the keys selected in the graph editor selectedChannels: Delete all the keys on selected channels visibleInGraphEditor: Only delete keys that are visible in the graph editor currentFrame: Delete the keys on the current frame deleteSubFrames: Delete sub-frame keys surrounding the current frame ''' sel = mc.ls(sl=True) if not sel: return channels = list() if selectedKeys and mc.keyframe(query=True, selected=True): #if selected keys (and keys are selected) just cut them mc.cutKey(includeUpperBound=False, sl=True, clear=True) return chanBoxChan = utl.getSelectedChannels() if selectedChannels and chanBoxChan: #if channel box (and channels are selected) curves = list() for obj in sel: for chan in chanBoxChan: temp = mc.listConnections('.'.join((obj, chan)), source=True, destination=False, type='animCurve') if temp: curves.append(temp[0]) if curves: mc.cutKey(curves, includeUpperBound=False, clear=True) utl.deselectChannels() return #past this point the options accumulate args = list() #animCurves = list() if visibleInGraphEditor and 'graphEditor1' in mc.getPanel( visiblePanels=True): #if visible in graph editor and graph editor is open graphVis = mc.selectionConnection('graphEditor1FromOutliner', query=True, obj=True) if graphVis: #animCurves = mc.keyframe(graphVis, query=True, name=True) args.append(mc.keyframe(graphVis, query=True, name=True)) kwargs = {'includeUpperBound': False, 'clear': True} if currentFrame: if not args: args = sel time = (mc.currentTime(query=True)) #include sub-frames in the time if deleteSubFrames and time % 1 == 0 and -9999 < time < 9999: kwargs['time'] = (time - 0.5, time + 0.5) else: kwargs['time'] = (time, ) if not args and (selectedKeys or selectedChannels or visibleInGraphEditor or currentFrame): #if there were any arguments, but tool hasn't found any curves, don't do anything return mc.cutKey(*args, **kwargs)
# Select CTL from fCurve selection Tool v003 import maya.cmds as cmds aObjList = [str(s) for s in cmds.selectionConnection('graphEditor1FromOutliner', q = True, object = True)] aCurveList = [str(s) for s in cmds.keyframe(query = True, name = True)] aSelectList = [] for o in aObjList: if not o in aSelectList: for c in aCurveList: sObj = '_'.join(c.split('_')[:-1]) if sObj in o: aSelectList.append(o) cmds.select(aSelectList, r = True)