Пример #1
0
def saveAttributeState(node, attribute, lock, hide):
    ''' Save an AttributeStates object to the given node on a PICKLED_ATTRIBUTE
    attribute.  Deletes that attribute if the AttributeStates object is not
    storing any changed states.'''
    attributeStates = getAttributeStates(node)
    attributeStates[attribute] = AttributeState('%s.%s' % (node, attribute), lock, hide)

    # Prune attribute from dict if it's being unset
    attributeStates.removeInactive()

    if not attributeStates.keys():
        # Remove attribute and exit function if it is no longer storing any states
        deletePickledAttribute(node)

    else:
        # Otherwise, store its state.
        pickle.toAttr('%s.%s' % (node, PICKLED_ATTRIBUTE), attributeStates, useLockHide=True)
Пример #2
0
def restoreAllAttributeStates(validateStates=True):
    ''' Restores all saved attribute states on all nodes with a
    PICKLED_ATTRIBUTE.

    When validateStates is true, this function will store the current state of
    every saved attribute as it's initial state.  Therefore it is VERY
    IMPORTANT that this function IS NOT RUN TWICE in a row with validateStates
    as true.  If it is, the modified states will be set as the initial states,
    invalidating the internal state machine which does not have any sort of
    check against this thing.  That is to say, running this method twice may
    seriously f**k up your work.

    It is important to run this command once (and only once) after a new scene
    load because referenced animation files will not save new locked or hidden
    states set from the custom lockHideAttribute command.'''
    for node in cmd.ls():
        attributeStates = getAttributeStates(node)
        if attributeStates.keys():
            # Force state validation
            if validateStates:
                for attribute in attributeStates.keys():
                    attributeStates[attribute].validateState('%s.%s' % (node, attribute))

            # Prune attribute from dict if it's being unset
            attributeStates.removeInactive()

            if not attributeStates.keys():
                # Remove attribute and exit function if it is no longer storing any states
                result = deletePickledAttribute(node)
            else:
                # Otherwise, store its state.
                pickle.toAttr('%s.%s' % (node, PICKLED_ATTRIBUTE), attributeStates, useLockHide=True)

                # Apply states
                for attribute in attributeStates.keys():
                    callLockHideCommand(node, attribute, attributeStates[attribute].lock, attributeStates[attribute].hide)