Ejemplo n.º 1
0
    def setVariantValues(self, values):
        attrPath = self.getAttrPath()
        if not attrPath:
            return

        for i, value in enumerate(values):
            strValue = serializeAttrValue(value)
            cmds.pulseSetActionAttr(attrPath, strValue, v=i)
Ejemplo n.º 2
0
    def setAttrValue(self, newValue):
        """
        Set the current value of the attribute in this form.
        Performs partial validation and prevents setting
        the value if it's type is invalid.
        """
        # value doesn't need to be valid as long
        # as it has the right type
        if self._isValueTypeValid(newValue):
            self.attrValue = newValue
            self._setFormValue(newValue)
            self.isValueValid = self._isValueValid(newValue)
            self._setUiValidState(self.isValueValid)

            # TODO: clean up relationship between preview value and actual value
            attrPath = self.getAttrPath()
            if not attrPath:
                return

            strValue = serializeAttrValue(newValue)
            cmds.pulseSetActionAttr(attrPath, strValue, v=self.variantIndex)
Ejemplo n.º 3
0
    def mirrorAction(self, sourceStep):
        """
        Mirror a BuildStep
        """
        if not self.canMirrorStep(sourceStep):
            LOG.warning(
                "Cannot mirror %s, only actions with"
                "symmetrical names can be mirrored", sourceStep)
            return False

        cmds.undoInfo(openChunk=True, chunkName='Mirror Action')

        destStep = self.getOrCreatePairedStep(sourceStep)
        if not destStep:
            return False

        sourceAction = sourceStep.actionProxy
        destAction = destStep.actionProxy

        if not destAction or destAction.getActionId(
        ) != sourceAction.getActionId():
            # action was setup incorrectly
            LOG.warning(
                "Cannot mirror %s -> %s, destination action"
                "is not tye same type", sourceStep, destStep)
            return False

        destStepPath = destStep.getFullPath()

        # match up variant attrs
        for attr in sourceAction.getAttrs():
            isVariant = sourceAction.isVariantAttr(attr['name'])
            attrPath = destStepPath + '.' + attr['name']
            if destAction.isVariantAttr(attr['name']) != isVariant:
                cmds.pulseSetIsVariantAttr(attrPath, isVariant)

        # match up variant lengths
        while sourceAction.numVariants() < destAction.numVariants():
            destAction.removeVariantAt(-1)
        while sourceAction.numVariants() > destAction.numVariants():
            destAction.addVariant()

        #  mirror invariant attr values
        for attr in sourceAction.getAttrs():
            if not sourceAction.isVariantAttr(attr['name']):
                value = sourceAction.getAttrValue(attr['name'])
                mirroredValue = self.mirrorActionValue(attr, value)
                attrPath = destStepPath + '.' + attr['name']
                mirroredValueStr = serializeAttrValue(mirroredValue)
                LOG.debug('%s -> %s', value, mirroredValue)
                cmds.pulseSetActionAttr(attrPath, mirroredValueStr)

        # mirror variant attr values
        for i in range(sourceAction.numVariants()):
            variant = sourceAction.getVariant(i)
            for attrName in sourceAction.getVariantAttrs():
                attr = variant.getAttrConfig(attrName)
                if not attr:
                    # possibly stale or removed attribute
                    continue
                value = variant.getAttrValue(attrName)
                mirroredValue = self.mirrorActionValue(attr, value)
                attrPath = destStepPath + '.' + attr['name']
                mirroredValueStr = serializeAttrValue(mirroredValue)
                LOG.debug('%s -> %s', value, mirroredValue)

                cmds.pulseSetActionAttr(attrPath, mirroredValueStr, v=i)

        cmds.undoInfo(closeChunk=True)

        return True