Python maya.cmds.channelBox() Examples

The following are 12 code examples of maya.cmds.channelBox(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module maya.cmds , or try the search function .
Example #1
Source File: ui.py    From maya-channel-box-plus with GNU General Public License v3.0 6 votes vote down vote up
def getChannelBoxMenu():
    """
    Get ChannelBox, convert the main channel box to QT and return the QMenu 
    which is part of the channel box' children.

    :return: Maya's main channel box menu
    :rtype: QMenu
    """
    channelBox = getChannelBox()
    
    for child in channelBox.children():
        if type(child) == QMenu:
            cmd = "generateChannelMenu {0} 1".format(qtToMaya(child))
            mel.eval(cmd)
            return child


# ---------------------------------------------------------------------------- 
Example #2
Source File: ml_utilities.py    From ml_tools with MIT License 6 votes vote down vote up
def getSelectedChannels():
    '''
    Return channels that are selected in the channelbox
    '''

    if not mc.ls(sl=True):
        return
    gChannelBoxName = mm.eval('$temp=$gChannelBoxName')
    sma = mc.channelBox(gChannelBoxName, query=True, sma=True)
    ssa = mc.channelBox(gChannelBoxName, query=True, ssa=True)
    sha = mc.channelBox(gChannelBoxName, query=True, sha=True)

    channels = list()
    if sma:
        channels.extend(sma)
    if ssa:
        channels.extend(ssa)
    if sha:
        channels.extend(sha)

    return channels 
Example #3
Source File: ml_utilities.py    From ml_tools with MIT License 6 votes vote down vote up
def _populateSelectionField(self, channel, field, *args):

        selectedChannels = None
        if channel:
            selectedChannels = getSelectedChannels()
            if not selectedChannels:
                raise RuntimeError('Please select an attribute in the channelBox.')
            if len(selectedChannels) > 1:
                raise RuntimeError('Please select only one attribute.')

        sel = mc.ls(sl=True)
        if not sel:
            raise RuntimeError('Please select a node.')
        if len(sel) > 1:
            raise RuntimeError('Please select only one node.')

        selection = sel[0]
        if selectedChannels:
            selection = selection+'.'+selectedChannels[0]

        mc.textFieldButtonGrp(field, edit=True, text=selection) 
Example #4
Source File: ml_utilities.py    From ml_tools with MIT License 6 votes vote down vote up
def _populateSelectionList(self, channel, control, *args):

        selectedChannels = None
        if channel:
            selectedChannels = getSelectedChannels()
            if not selectedChannels:
                raise RuntimeError('Please select an attribute in the channelBox.')
            if len(selectedChannels) > 1:
                raise RuntimeError('Please select only one attribute.')

        sel = mc.ls(sl=True)
        if not sel:
            raise RuntimeError('Please select a node.')
        if len(sel) > 1:
            raise RuntimeError('Please select only one node.')

        selection = sel[0]
        if selectedChannels:
            selection = selection+'.'+selectedChannels[0]

        mc.textScrollList(control, edit=True, append=[selection]) 
Example #5
Source File: dpControls.py    From dpAutoRigSystem with GNU General Public License v2.0 5 votes vote down vote up
def setNonKeyable(self, objList, attrList, *args):
        """Set nonKeyable to attributes for objects in lists.
        """
        if objList and attrList:
            for obj in objList:
                for attr in attrList:
                    if cmds.objExists(obj+"."+attr):
                        try:
                            # set lock and hide of given attributes:
                            cmds.setAttr(obj+"."+attr, keyable=False, channelBox=True)
                        except:
                            print "Error: Cannot set", obj, ".", attr, "as nonKeayble, sorry." 
Example #6
Source File: dpControls.py    From dpAutoRigSystem with GNU General Public License v2.0 5 votes vote down vote up
def copyAttr(self, sourceItem=False, attrList=False, verbose=False, *args):
        """ Get and store in a dictionary the attributes from sourceItem.
            Returns the dictionary with attribute values.
        """
        # getting sourceItem:
        if not sourceItem:
            selList = cmds.ls(selection=True, long=True)
            if selList:
                sourceItem = selList[0]
            else:
                print self.dpUIinst.langDic[self.dpUIinst.langName]["e015_selectToCopyAttr"]
        if cmds.objExists(sourceItem):
            if not attrList:
                # getting channelBox selected attributes:
                currentAttrList = cmds.channelBox('mainChannelBox', query=True, selectedMainAttributes=True)
                if not currentAttrList:
                    # list all attributes if nothing is selected:
                    currentAttrList = cmds.listAttr(sourceItem, visible=True, keyable=True)
                attrList = currentAttrList
            if attrList:
                # store attribute values in a dic:
                self.attrValueDic = {}
                for attr in attrList:
                    if cmds.objExists(sourceItem+'.'+attr):
                        value = cmds.getAttr(sourceItem+'.'+attr)
                        self.attrValueDic[attr] = value
                if verbose:
                    print self.dpUIinst.langDic[self.dpUIinst.langName]["i125_copiedAttr"]
        return self.attrValueDic 
Example #7
Source File: ui.py    From maya-channel-box-plus with GNU General Public License v3.0 5 votes vote down vote up
def getChannelBox():
    """
    Get ChannelBox, convert the main channel box to QT.

    :return: Maya's main channel box
    :rtype: QWidget
    """
    channelBox = mayaToQT(CHANNELBOX)
    return channelBox 
Example #8
Source File: ui.py    From maya-channel-box-plus with GNU General Public License v3.0 5 votes vote down vote up
def updateSearch(self, matchString, nodes):    
        """
        Loop over all keyable attributes and match them with the search string.
        
        :param str matchString: Search string to match with attributes
        :param list nodes: List of nodes to process the attributes from
        """
        # reset of search string is empty
        if not matchString:
            cmds.channelBox(CHANNELBOX, edit=True, fixedAttrList=[])
            return
    
        # split match string
        matches = []
        matchStrings = matchString.lower().split()
        
        # get matching attributes
        for node in nodes:
            attrs = cmds.listAttr(node, k=True, v=True)
            
            for attr in attrs:
                if (
                    not attr in matches and 
                    self.matchSearch(attr, matchStrings)
                ):
                    matches.append(attr)
               
        # append null if not matches are found ( cannot use empty list )
        if not matches:
            matches.append("null")

        # filter channel box
        cmds.channelBox(CHANNELBOX, edit=True, fixedAttrList=matches)
        
    # ------------------------------------------------------------------------ 
Example #9
Source File: ui.py    From maya-channel-box-plus with GNU General Public License v3.0 5 votes vote down vote up
def install(threshold=0.75):
    """
    Add the search interface and colouring functionality to Maya's main
    channel box. If channelBoxPlus is already installed a RuntimeError
    exception will be thrown. A threshold can be set, this threshold
    determines when the attributes should change colour. the higher the
    threshold the more the 2 attributes will have to match up to stay the same
    colour.

    :param float threshold: Threshold for attribute colour change
    :raises RuntimeError: When the channel box plus is already installed.
    """
    global CHANNELBOX_PLUS

    # validate channel box plus
    if CHANNELBOX_PLUS:
        raise RuntimeError("Channel box plus is already installed!")

    # get channel box
    channelBox = getChannelBox()

    # get channel box layout
    parent = channelBox.parent()
    layout = parent.layout()
    layout.setSpacing(0)

    # initialize search widget
    CHANNELBOX_PLUS = SearchWidget(parent, threshold)

    # add search widget to layout
    if type(layout) == QLayout:
        item = layout.itemAt(0)
        widget = item.widget()

        layout.removeWidget(widget)
        layout.addWidget(CHANNELBOX_PLUS)
        layout.addWidget(widget)
    else:
        layout.insertWidget(0, CHANNELBOX_PLUS) 
Example #10
Source File: ml_resetChannels.py    From ml_tools with MIT License 5 votes vote down vote up
def main(selectedChannels=True, transformsOnly=False, excludeChannels=None):
    '''
    Resets selected channels in the channel box to default, or if nothing's
    selected, resets all keyable channels to default.
    '''
    gChannelBoxName = mm.eval('$temp=$gChannelBoxName')

    sel = mc.ls(sl=True)
    if not sel:
        return

    if excludeChannels and not isinstance(excludeChannels, (list, tuple)):
        excludeChannels = [excludeChannels]

    chans = None
    if selectedChannels:
        chans = mc.channelBox(gChannelBoxName, query=True, sma=True)

    testList = ['translateX','translateY','translateZ','rotateX','rotateY','rotateZ','scaleX','scaleY','scaleZ',
                'tx','ty','yz','rx','ry','rz','sx','sy','sz']
    for obj in sel:
        attrs = chans
        if not chans:
            attrs = mc.listAttr(obj, keyable=True, unlocked=True)
            if excludeChannels and attrs:
                attrs = [x for x in attrs if x not in excludeChannels]
        if transformsOnly:
            attrs = [x for x in attrs if x in testList]
        if attrs:
            for attr in attrs:
                try:
                    default = mc.attributeQuery(attr, listDefault=True, node=obj)[0]
                    mc.setAttr(obj+'.'+attr, default)
                except StandardError:
                    pass

    utl.deselectChannels() 
Example #11
Source File: ml_utilities.py    From ml_tools with MIT License 5 votes vote down vote up
def deselectChannels():
    '''
    Deselect selected channels in the channelBox
    by clearing selection and then re-selecting
    '''

    if not getSelectedChannels():
        return
    sel = mc.ls(sl=True)
    mc.select(clear=True)
    mc.evalDeferred(partial(mc.select,sel)) 
Example #12
Source File: customAttributeEditor.py    From DeformationLearningSolver with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
def on_add_btn_clicked(self):
        
        selNodes = cmds.ls(sl=1, ap=1)
        if not selNodes:
            om.MGlobal.displayError("Please select some nodes and attributes.")
            return
        
        selAttrs = (cmds.channelBox("mainChannelBox", q=1, sma=1) or []) \
            + (cmds.channelBox("mainChannelBox", q=1, sha=1) or []) \
            + (cmds.channelBox("mainChannelBox", q=1, ssa=1) or []) \
            + (cmds.channelBox("mainChannelBox", q=1, soa=1) or [])
        
        if not selAttrs:
            selAttrs = cmds.listAttr(selNodes, v=1, k=1, sn=1)
            selAttrs = list(set(selAttrs))
            try:
                selAttrs.remove('v')
            except:
                pass
        
        self.table.clearSelection()
        
        for node in selNodes:
            for attr in selAttrs:
                name = "%s.%s" % (node, attr)
                minVal, maxVal = 0.0, 1.0
                hasMinVal, hasMaxVal = False, False
                
                if not cmds.objExists(name):
                    continue
                
                # Set minVal
                if cmds.attributeQuery(attr, node=node, minExists=1):
                    minVal = cmds.attributeQuery(attr, node=node, min=1)[0]
                    hasMinVal = True
                
                if cmds.attributeQuery(attr, node=node, softMinExists=1):
                    minVal = cmds.attributeQuery(attr, node=node, smn=1)[0]
                    hasMinVal = True
                
                # Set maxVal    
                if cmds.attributeQuery(attr, node=node, maxExists=1):
                    maxVal = cmds.attributeQuery(attr, node=node, max=1)[0]
                    hasMaxVal = True
                
                if cmds.attributeQuery(attr, node=node, softMaxExists=1):
                    maxVal = cmds.attributeQuery(attr, node=node, smx=1)[0]
                    hasMaxVal = True
                
                currVal = cmds.getAttr(name)
                if hasMinVal: minVal = minVal - currVal
                if hasMaxVal: maxVal = maxVal - currVal
                    
                self.appendRow()
                self.setRow(self.numRow()-1, [name, minVal, maxVal])
    
    #----------------------------------------------------------------------