def resetAttributeState(attribute, lock=True, hide=True):
    ''' Resets the lock/hidden state on the given attribute. Cleanup is handled
    in saveAttributeState.'''

    node, attribute = selectedAttributes.splitAttr(attribute)
    attributeStates = getAttributeStates(node)

    if attribute in attributeStates.keys():
        kwargs = {'lock': -1, 'hide': -1}
        if lock:
            kwargs['lock'] = attributeStates[attribute].initialLockState
        if hide:
            kwargs['hide'] = attributeStates[attribute].initialHideState
        lockHideAttribute('%s.%s' % (node, attribute), **kwargs)
Ejemplo n.º 2
0
def resetAttributeState(attribute, lock=True, hide=True):
    ''' Resets the lock/hidden state on the given attribute. Cleanup is handled
    in saveAttributeState.'''

    node, attribute = selectedAttributes.splitAttr(attribute)
    attributeStates = getAttributeStates(node)

    if attribute in attributeStates.keys():
        kwargs = {'lock': -1, 'hide': -1}
        if lock:
            kwargs['lock'] = attributeStates[attribute].initialLockState
        if hide:
            kwargs['hide'] = attributeStates[attribute].initialHideState
        lockHideAttribute('%s.%s' % (node, attribute), **kwargs)
def getFirstConnection(node, attribute=None, inAttr=1, outAttr=None, findAttribute=0):
    '''An quick way to get a single object from an incoming or outgoing
    connection.'''
    if attribute is None:
        node, attribute = selectedAttributes.splitAttr(node)
        if not attribute:
            om.MGlobal.displayInfo('Node %s has no attribute passed.  An attribute is needed to find a connection!' % node)

    if outAttr is None:
        outAttr = not inAttr
    else:
        inAttr = not outAttr

    try:
        nodes = cmd.listConnections('%s.%s' % (node, attribute), d=outAttr, s=inAttr, scn=1, p=findAttribute)
        if nodes:
            return nodes[0]
    except RuntimeError:
        om.MGlobal.displayWarning('%s has no attribute %s' % (node, attribute))
def lockHideAttribute(fullAttribute, lock=-1, hide=-1, override=False):
    ''' Can lock, hide or unlock and unhide referenced attributes using the
    custom lockHideAttribute command.  Assumes that all attributes are on
    a referenced object.

    Has a saftey feature in place to not unlock or unhide any previously locked
    or hidden attribute.  The override parameter will override this, however
    the restoreAllAttributeStates method will erase any state saved this way on
    file-load.  Therefore THE OVERRIDE METHOD IS ONLY AVALIABLE TO DEVELOPERS.

    Pass lock or hide 1 or 0 to set an attribute as locked or hidden.  Pass -1
    to not affect the current state.

    resetAttributeState and resetNodeState should be used to restore prior
    states.

    Attributes set back to their original values will be cleaned automatically.
    '''
    node, attribute = selectedAttributes.splitAttr(fullAttribute)

    # Saftey check to stop unhiding or unlocking locked referenced attributes
    # to help maintain asset integrity.
    if not override:
        attributeStates = getAttributeStates(node)
        if attribute in attributeStates.keys():
            if lock == 0 and attributeStates[attribute].initialLockState == 1:
                om.MGlobal.displayWarning((
                    "Lock 'n Hide: Skipping %s because it was initially "
                    "locked.  Use the override flag if you still want to "
                    "unlock this attribute.") % fullAttribute)
                return
            if hide == 0 and attributeStates[attribute].initialHideState == 1:
                om.MGlobal.displayWarning((
                    "Lock 'n Hide: Skipping %s because it was initially "
                    "hidden.  Use the override flag if you still want to "
                    "unhide this attribute.") % fullAttribute)
                return

    # Apply command
    saveAttributeState(node, attribute, lock, hide)
    callLockHideCommand(node, attribute, lock, hide)
Ejemplo n.º 5
0
def lockHideAttribute(fullAttribute, lock=-1, hide=-1, override=False):
    ''' Can lock, hide or unlock and unhide referenced attributes using the
    custom lockHideAttribute command.  Assumes that all attributes are on
    a referenced object.

    Has a saftey feature in place to not unlock or unhide any previously locked
    or hidden attribute.  The override parameter will override this, however
    the restoreAllAttributeStates method will erase any state saved this way on
    file-load.  Therefore THE OVERRIDE METHOD IS ONLY AVALIABLE TO DEVELOPERS.

    Pass lock or hide 1 or 0 to set an attribute as locked or hidden.  Pass -1
    to not affect the current state.

    resetAttributeState and resetNodeState should be used to restore prior
    states.

    Attributes set back to their original values will be cleaned automatically.
    '''
    node, attribute = selectedAttributes.splitAttr(fullAttribute)

    # Saftey check to stop unhiding or unlocking locked referenced attributes
    # to help maintain asset integrity.
    if not override:
        attributeStates = getAttributeStates(node)
        if attribute in attributeStates.keys():
            if lock == 0 and attributeStates[attribute].initialLockState == 1:
                om.MGlobal.displayWarning(
                    ("Lock 'n Hide: Skipping %s because it was initially "
                     "locked.  Use the override flag if you still want to "
                     "unlock this attribute.") % fullAttribute)
                return
            if hide == 0 and attributeStates[attribute].initialHideState == 1:
                om.MGlobal.displayWarning(
                    ("Lock 'n Hide: Skipping %s because it was initially "
                     "hidden.  Use the override flag if you still want to "
                     "unhide this attribute.") % fullAttribute)
                return

    # Apply command
    saveAttributeState(node, attribute, lock, hide)
    callLockHideCommand(node, attribute, lock, hide)
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)