Python maya.cmds.deleteAttr() Examples

The following are 9 code examples of maya.cmds.deleteAttr(). 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: dpUtils.py    From dpAutoRigSystem with GNU General Public License v2.0 5 votes vote down vote up
def zeroOut(transformList=[], offset=False):
    """ Create a group over the transform, parent the transform in it and set zero all transformations of the transform node.
        If don't have a transformList given, try to get the current selection.
        If want to create with offset, it'll be a, offset group between zeroGrp and transform.
        Return a list of names of the zeroOut groups.
    """
    zeroList = []
    if not transformList:
        transformList = cmds.ls(selection=True)
    if transformList:
        for transform in transformList:
            zeroGrp = cmds.duplicate(transform, name=transform+'_Zero_Grp')[0]
            zeroUserAttrList = cmds.listAttr(zeroGrp, userDefined=True)
            if zeroUserAttrList:
                for zUserAttr in zeroUserAttrList:
                    try:
                        cmds.deleteAttr(zeroGrp+"."+zUserAttr)
                    except:
                        pass
            allChildrenList = cmds.listRelatives(zeroGrp, allDescendents=True, children=True, fullPath=True)
            if allChildrenList:
                cmds.delete(allChildrenList)
            if offset:
                offsetGrp = cmds.duplicate(zeroGrp, name=transform+'_Offset_Grp')[0]
                cmds.parent(transform, offsetGrp, absolute=True)
                cmds.parent(offsetGrp, zeroGrp, absolute=True)
            else:
                cmds.parent(transform, zeroGrp, absolute=True)
            zeroList.append(zeroGrp)
    return zeroList 
Example #2
Source File: dpUtils.py    From dpAutoRigSystem with GNU General Public License v2.0 5 votes vote down vote up
def clearDpArAttr(itemList):
    """ Delete all dpAR (dpAutoRigSystem) attributes in this joint
    """
    dpArAttrList = ['dpAR_joint']
    if itemList:
        for item in itemList:
            for dpArAttr in dpArAttrList:
                if cmds.objExists(item+"."+dpArAttr):
                    cmds.deleteAttr(item+"."+dpArAttr) 
Example #3
Source File: mayauserprops.py    From cross3d with MIT License 5 votes vote down vote up
def __delitem__(self, key):
		if not key in self:
			raise KeyError('{} is not stored in UserProps'.format(key))
		cmds.deleteAttr(cross3d.SceneWrapper._mObjName(self._nativePointer), attribute=key) 
Example #4
Source File: plot.py    From cmdx with BSD 2-Clause "Simplified" License 5 votes vote down vote up
def teardown():
    cmds.deleteAttr("transform1.myAttr") 
Example #5
Source File: BlendTransforms.py    From BlendTransforms with The Unlicense 4 votes vote down vote up
def BT_DeletePose(set = None, poseIndex = None):

    if not set or poseIndex is None:
        return False
    
    if not cmds.attributeQuery('Blend_Node', ex = True, n = set):
        return False

    if BT_IsSetupConnected(set):
        cmds.warning('Disconnect setup first!')
        return False

    blendNode = cmds.getAttr(set +'.Blend_Node')

    if not cmds.objExists(blendNode) or not cmds.objExists(set):
        return False

    numTransforms = cmds.getAttr(blendNode +'.transforms', size = True)

    if not numTransforms:
        return False

    numPoses = cmds.getAttr(blendNode +'.transforms[0].poses', size = True) 
    allUserDefined = cmds.listAttr(set, ud = True)
    btUserDefined = [x for x in allUserDefined if x.startswith('BT_')]

    if poseIndex >= numPoses:
        return False

    connectionsToBreak = cmds.listConnections(set +'.' +btUserDefined[poseIndex], d = True, s = False, p = True)
    for ctb in connectionsToBreak:
        cmds.disconnectAttr(set +'.' +btUserDefined[poseIndex], ctb)
    cmds.deleteAttr(set +'.' +btUserDefined[poseIndex])

    for i in range(0, numTransforms):
        for p in range(poseIndex, numPoses-1):
            #get the next items vales
            matrix = cmds.getAttr(blendNode +'.transforms[' +str(i) +'].poses[' +str(p+1) +'].matrix')
            scale = cmds.getAttr(blendNode +'.transforms[' +str(i) +'].poses[' +str(p+1) +'].scale')[0]
            conn = cmds.listConnections(blendNode +'.transforms[' +str(i) +'].poses[' +str(p+1) +'].weight', s = True, d = False, p = True)[0]

            cmds.setAttr(blendNode +'.transforms[' +str(i) +'].poses[' +str(p) +'].matrix', matrix, type = 'matrix')
            cmds.setAttr(blendNode +'.transforms[' +str(i) +'].poses[' +str(p) +'].scale', scale[0], scale[1], scale[2], type = 'double3')
            cmds.connectAttr(conn, blendNode +'.transforms[' +str(i) +'].poses[' +str(p) +'].weight', force = True)
            cmds.disconnectAttr(conn, blendNode +'.transforms[' +str(i) +'].poses[' +str(p+1) +'].weight')

    return True 
Example #6
Source File: BlendTransforms.py    From BlendTransforms with The Unlicense 4 votes vote down vote up
def BT_DeletePose(set = None, poseIndex = None):

    if not set or poseIndex is None:
        return False
    
    if not cmds.attributeQuery('Blend_Node', ex = True, n = set):
        return False

    if BT_IsSetupConnected(set):
        cmds.warning('Disconnect setup first!')
        return False

    blendNode = cmds.getAttr(set +'.Blend_Node')

    if not cmds.objExists(blendNode) or not cmds.objExists(set):
        return False

    numTransforms = cmds.getAttr(blendNode +'.transforms', size = True)

    if not numTransforms:
        return False

    numPoses = cmds.getAttr(blendNode +'.transforms[0].poses', size = True) 
    allUserDefined = cmds.listAttr(set, ud = True)
    btUserDefined = [x for x in allUserDefined if x.startswith('BT_')]

    if poseIndex >= numPoses:
        return False

    connectionsToBreak = cmds.listConnections(set +'.' +btUserDefined[poseIndex], d = True, s = False, p = True)
    for ctb in connectionsToBreak:
        cmds.disconnectAttr(set +'.' +btUserDefined[poseIndex], ctb)
    cmds.deleteAttr(set +'.' +btUserDefined[poseIndex])

    for i in range(0, numTransforms):
        for p in range(poseIndex, numPoses-1):
            #get the next items vales
            matrix = cmds.getAttr(blendNode +'.transforms[' +str(i) +'].poses[' +str(p+1) +'].matrix')
            scale = cmds.getAttr(blendNode +'.transforms[' +str(i) +'].poses[' +str(p+1) +'].scale')[0]
            conn = cmds.listConnections(blendNode +'.transforms[' +str(i) +'].poses[' +str(p+1) +'].weight', s = True, d = False, p = True)[0]

            cmds.setAttr(blendNode +'.transforms[' +str(i) +'].poses[' +str(p) +'].matrix', matrix, type = 'matrix')
            cmds.setAttr(blendNode +'.transforms[' +str(i) +'].poses[' +str(p) +'].scale', scale[0], scale[1], scale[2], type = 'double3')
            cmds.connectAttr(conn, blendNode +'.transforms[' +str(i) +'].poses[' +str(p) +'].weight', force = True)
            cmds.disconnectAttr(conn, blendNode +'.transforms[' +str(i) +'].poses[' +str(p+1) +'].weight')

    return True 
Example #7
Source File: BlendTransforms.py    From BlendTransforms with The Unlicense 4 votes vote down vote up
def BT_DeletePose(set = None, poseIndex = None):

    if not set or poseIndex is None:
        return False
    
    if not cmds.attributeQuery('Blend_Node', ex = True, n = set):
        return False

    if BT_IsSetupConnected(set):
        cmds.warning('Disconnect setup first!')
        return False

    blendNode = cmds.getAttr(set +'.Blend_Node')

    if not cmds.objExists(blendNode) or not cmds.objExists(set):
        return False

    numTransforms = cmds.getAttr(blendNode +'.transforms', size = True)

    if not numTransforms:
        return False

    numPoses = cmds.getAttr(blendNode +'.transforms[0].poses', size = True) 
    allUserDefined = cmds.listAttr(set, ud = True)
    btUserDefined = [x for x in allUserDefined if x.startswith('BT_')]

    if poseIndex >= numPoses:
        return False

    connectionsToBreak = cmds.listConnections(set +'.' +btUserDefined[poseIndex], d = True, s = False, p = True)
    for ctb in connectionsToBreak:
        cmds.disconnectAttr(set +'.' +btUserDefined[poseIndex], ctb)
    cmds.deleteAttr(set +'.' +btUserDefined[poseIndex])

    for i in range(0, numTransforms):
        for p in range(poseIndex, numPoses-1):
            #get the next items vales
            matrix = cmds.getAttr(blendNode +'.transforms[' +str(i) +'].poses[' +str(p+1) +'].matrix')
            scale = cmds.getAttr(blendNode +'.transforms[' +str(i) +'].poses[' +str(p+1) +'].scale')[0]
            conn = cmds.listConnections(blendNode +'.transforms[' +str(i) +'].poses[' +str(p+1) +'].weight', s = True, d = False, p = True)[0]

            cmds.setAttr(blendNode +'.transforms[' +str(i) +'].poses[' +str(p) +'].matrix', matrix, type = 'matrix')
            cmds.setAttr(blendNode +'.transforms[' +str(i) +'].poses[' +str(p) +'].scale', scale[0], scale[1], scale[2], type = 'double3')
            cmds.connectAttr(conn, blendNode +'.transforms[' +str(i) +'].poses[' +str(p) +'].weight', force = True)
            cmds.disconnectAttr(conn, blendNode +'.transforms[' +str(i) +'].poses[' +str(p+1) +'].weight')

    return True 
Example #8
Source File: BlendTransforms.py    From BlendTransforms with The Unlicense 4 votes vote down vote up
def BT_DeletePose(set = None, poseIndex = None):

    if not set or poseIndex is None:
        return False
    
    if not cmds.attributeQuery('Blend_Node', ex = True, n = set):
        return False

    if BT_IsSetupConnected(set):
        cmds.warning('Disconnect setup first!')
        return False

    blendNode = cmds.getAttr(set +'.Blend_Node')

    if not cmds.objExists(blendNode) or not cmds.objExists(set):
        return False

    numTransforms = cmds.getAttr(blendNode +'.transforms', size = True)

    if not numTransforms:
        return False

    numPoses = cmds.getAttr(blendNode +'.transforms[0].poses', size = True) 
    allUserDefined = cmds.listAttr(set, ud = True)
    btUserDefined = [x for x in allUserDefined if x.startswith('BT_')]

    if poseIndex >= numPoses:
        return False

    connectionsToBreak = cmds.listConnections(set +'.' +btUserDefined[poseIndex], d = True, s = False, p = True)
    for ctb in connectionsToBreak:
        cmds.disconnectAttr(set +'.' +btUserDefined[poseIndex], ctb)
    cmds.deleteAttr(set +'.' +btUserDefined[poseIndex])

    for i in range(0, numTransforms):
        for p in range(poseIndex, numPoses-1):
            #get the next items vales
            matrix = cmds.getAttr(blendNode +'.transforms[' +str(i) +'].poses[' +str(p+1) +'].matrix')
            scale = cmds.getAttr(blendNode +'.transforms[' +str(i) +'].poses[' +str(p+1) +'].scale')[0]
            conn = cmds.listConnections(blendNode +'.transforms[' +str(i) +'].poses[' +str(p+1) +'].weight', s = True, d = False, p = True)[0]

            cmds.setAttr(blendNode +'.transforms[' +str(i) +'].poses[' +str(p) +'].matrix', matrix, type = 'matrix')
            cmds.setAttr(blendNode +'.transforms[' +str(i) +'].poses[' +str(p) +'].scale', scale[0], scale[1], scale[2], type = 'double3')
            cmds.connectAttr(conn, blendNode +'.transforms[' +str(i) +'].poses[' +str(p) +'].weight', force = True)
            cmds.disconnectAttr(conn, blendNode +'.transforms[' +str(i) +'].poses[' +str(p+1) +'].weight')

    return True 
Example #9
Source File: spaceswitch.py    From cmt with MIT License 4 votes vote down vote up
def create_space_switch(
    node, drivers, switch_attribute=None, use_translate=True, use_rotate=True
):
    """Creates a space switch network.

    The network uses the offsetParentMatrix attribute and does not create any
    constraints or new dag nodes.

    :param node: Transform to drive
    :param drivers: List of tuples: [(driver1, "spaceName1"), (driver2, "spaceName2")]
    :param switch_attribute: Name of the switch attribute to create on the target node.
    """
    if switch_attribute is None:
        switch_attribute = "space"

    if cmds.objExists("{}.{}".format(node, switch_attribute)):
        cmds.deleteAttr(node, at=switch_attribute)
    names = [d[1] for d in drivers]
    cmds.addAttr(node, ln=switch_attribute, at="enum", en=":".join(names), keyable=True)

    # Create attribute to toggle translation in the matrices
    enable_translate_attr = _create_bool_attribute(
        node, "{}UseTranslate".format(switch_attribute), use_translate
    )

    # Create attribute to toggle rotation in the matrices
    enable_rotate_attr = _create_bool_attribute(
        node, "{}UseRotate".format(switch_attribute), use_rotate
    )

    blend = cmds.createNode("blendMatrix", name="{}_spaceswitch".format(node))

    # Get the current offset parent matrix.  This is used as the starting blend point
    m = OpenMaya.MMatrix(cmds.getAttr("{}.offsetParentMatrix".format(node)))
    cmds.setAttr("{}.inputMatrix".format(blend), list(m), type="matrix")

    parent = cmds.listRelatives(node, parent=True, path=True)
    to_parent_local = "{}.worldInverseMatrix[0]".format(parent[0]) if parent else None

    for i, driver in enumerate(drivers):
        driver = driver[0]

        _connect_driver_matrix_network(blend, node, driver, i, to_parent_local)

        target_attr = "{}.target[{}]".format(blend, i)

        # Hook up the weight toggle when switching spaces
        dge(
            "x = switch == {} ? 1 : 0".format(i),
            x="{}.weight".format(target_attr),
            switch="{}.{}".format(node, switch_attribute),
        )

        # Connect the translation, rotation toggles
        cmds.connectAttr(enable_translate_attr, "{}.useTranslate".format(target_attr))
        cmds.connectAttr(enable_rotate_attr, "{}.useRotate".format(target_attr, i))

    cmds.connectAttr(
        "{}.outputMatrix".format(blend), "{}.offsetParentMatrix".format(node)
    )