Python pymel.core.delete() Examples

The following are 30 code examples of pymel.core.delete(). 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 pymel.core , or try the search function .
Example #1
Source File: publish.py    From anima with MIT License 7 votes vote down vote up
def cleanup_intermediate_objects(progress_controller=None):
    """Delete unused intermediate objects

    deletes any unused intermediate object in the current scene
    """
    if progress_controller is None:
        progress_controller = ProgressControllerBase()

    unused_intermediate_objects = []
    all_meshes = pm.ls(type='mesh')
    progress_controller.maximum = len(all_meshes)
    for node in all_meshes:
        if len(node.inputs()) == 0 \
           and len(node.outputs()) == 0 \
           and node.intermediateObject.get() \
           and node.referenceFile() is None:
            unused_intermediate_objects.append(node)
        progress_controller.increment()
    pm.delete(unused_intermediate_objects)
    progress_controller.complete() 
Example #2
Source File: joint.py    From anima with MIT License 6 votes vote down vote up
def orient_choose_direction(self, joint, jointUnder, frontAxis):
        #TODO : Validate frontAxis
        if frontAxis == "x":
            frontInt = 0
        elif frontAxis == "z":
            frontInt = 2
        returnVal = 1

        transform_1 = DrawNode(Shape.transform, 'direction1')
        transform_1.temp_constrain(joint)

        transform_2 = DrawNode(Shape.transform, "direction2")
        transform_2.temp_constrain(jointUnder)

        frontTransform = transform_1.transform[frontInt] - \
                         transform_2.transform[frontInt]
        if frontTransform > 0:
            returnVal = -1
        transform_1.delete()
        transform_2.delete()

        return returnVal 
Example #3
Source File: joint.py    From anima with MIT License 6 votes vote down vote up
def set_zero_joint(self):

        #Removes Zero Joint from Joint Chain
        pm.joint(self.jointChain[0], e=True, zso=True, oj='xyz', sao='xup')
        self.zeroJoint = self.jointChain[0]

        self._zeroPos = pm.dt.Point(pm.getAttr(self._zeroJoint.translate))
        self.jointChain.remove(self.jointChain[0])
        self.jointPos.remove(self.jointPos[0])
        pm.joint(self.jointChain[1], e=True, zso=True, oj='xyz', sao='yup')
        for i in range(1, len(self.jointChain)):
            pm.joint(self.jointChain[i], e=True, zso=True, oj='xyz', sao='yup')
            #sets Start End Num Of Joints again
        self._numOfJoints = len(self._jointChain)
        #Orient Zero Joint
        temporalGroup = DrawNode(Shape.transform, 'temporalGroup')
        pm.parent(self.startJoint, temporalGroup.drawnNode)

        print(pm.getAttr(self.zeroJoint.jointOrient))
        pm.setAttr(self.zeroJoint.jointOrientX, 0)
        pm.parent(self.startJoint, self.zeroJoint)
        temporalGroup.delete() 
Example #4
Source File: previs.py    From anima with MIT License 6 votes vote down vote up
def delete_all_others(self, shot):  # delete all useless shots and cameras
        special_cams = ['perspShape', 'frontShape', 'sideShape', 'topShape']
        unused_shots = pm.ls(type="shot")
        # unused_camera = pm.ls("camera*", type="transform")
        unused_camera = [node.getParent()
                         for node in pm.ls(type='camera')
                         if node.name() not in special_cams]

        clear_cams_list = set(unused_camera)
        sel_camera = shot.currentCamera.get()

        unused_shots.remove(shot)
        clear_cams_list.remove(sel_camera)

        pm.delete(unused_shots)
        pm.delete(clear_cams_list)
        shot.track.set(1)
        print("shot is in order") 
Example #5
Source File: previs.py    From anima with MIT License 6 votes vote down vote up
def clear_scene(self, keep_shot):
        # delete all other shot nodes
        all_shots = pm.ls(type='shot')
        shots_to_delete = []
        for shot in all_shots:
            if shot.name() != keep_shot.name():
                shots_to_delete.append(shot)
        for shot in shots_to_delete:
            if shot:
                pm.delete(shot)

        # set some attrs and delete cameras
        if keep_shot:
            keep_shot.track.set(1)
            keep_shot.shotName.lock()

            shot_camera = keep_shot.currentCamera.get()
            exclude_cams = ['perspShape', 'frontShape', 'sideShape', 'topShape', shot_camera.getShape()]
            unused_cameras = [node.getParent()
                              for node in pm.ls(type='camera')
                              if node.name() not in exclude_cams]
            pm.delete(unused_cameras) 
Example #6
Source File: rigging.py    From anima with MIT License 6 votes vote down vote up
def duplicate(self, class_=None, prefix="", suffix=""):
        """duplicates itself and returns a new joint hierarchy

        :param class_: The class of the created JointHierarchy. Default value
          is JointHierarchy
        :param prefix: Prefix for newly created joints
        :param suffix: Suffix for newly created joints
        """
        if class_ is None:
            class_ = self.__class__

        new_start_joint = pm.duplicate(self.start_joint)[0]
        all_hierarchy = list(reversed(new_start_joint.listRelatives(ad=1, type=pm.nt.Joint)))
        new_end_joint = all_hierarchy[len(self.joints) - 2]

        # delete anything below
        pm.delete(new_end_joint.listRelatives(ad=1))

        new_hierarchy = class_(start_joint=new_start_joint, end_joint=new_end_joint)
        for j, nj in zip(self.joints, new_hierarchy.joints):
            nj.rename("{prefix}{joint}{suffix}".format(prefix=prefix, suffix=suffix, joint=j.name()))

        return new_hierarchy 
Example #7
Source File: drawNode.py    From anima with MIT License 6 votes vote down vote up
def create_axialCor(self):
        # Create Axial Correction group
        if self._axialCor is not None:
            temp_grp = pm.group(self.drawnNode, n=(self._axialCor + "_#"))
            self.ofsGrp.append(temp_grp)
        else:
            name = (self.drawnNode + "_axialCor")
            self._axialCor = self._draw(Shape.transform,
                                        (name))

            pm.delete(pm.parentConstraint(self.drawnNode, self.axialCor, mo=0))
            pm.parent(self._drawnNode, self._axialCor)
            #pm.delete(self.create_parentConst(self.drawnNode, self.axialCor))
            #pm.parent(self._drawnNode, self.axialCor)

    # Create Point Constrain 
Example #8
Source File: vertigo.py    From anima with MIT License 6 votes vote down vote up
def delete(camera):
    """deletes the vertigo setup from the given camera
    """

    global vertigo_attr_name
    global vertigo_global_attr_name

    camera_shape = camera.getShape()

    expression = camera_shape.connections(type=pm.nt.Expression)
    vertigo_loc = camera.attr(vertigo_attr_name).inputs()[0]
    world_loc = camera.attr(vertigo_global_attr_name).inputs()[0]

    # delete them
    pm.delete(expression)
    pm.delete(vertigo_loc)
    pm.delete(world_loc) 
Example #9
Source File: validate_intermediate_shapes.py    From pyblish-bumpybox with GNU Lesser General Public License v3.0 6 votes vote down vote up
def process(self, context, plugin):
        import pymel.core as pm

        # Get the errored instances
        failed = []
        for result in context.data["results"]:
            if (result["error"] is not None and result["instance"] is not None
               and result["instance"] not in failed):
                failed.append(result["instance"])

        # Apply pyblish.logic to get the instances for the plug-in
        instances = api.instances_by_plugin(failed, plugin)

        for instance in instances:
            for node in instance[0].members():
                io = pm.ls(node.getShapes(), intermediateObjects=True)
                pm.delete(io) 
Example #10
Source File: validate_points.py    From pyblish-bumpybox with GNU Lesser General Public License v3.0 6 votes vote down vote up
def process(self, context, plugin):
        import pymel.core as pm

        # Get the errored instances
        failed = []
        for result in context.data["results"]:
            if (result["error"] is not None and result["instance"] is not None
               and result["instance"] not in failed):
                failed.append(result["instance"])

        # Apply pyblish.logic to get the instances for the plug-in
        instances = api.instances_by_plugin(failed, plugin)

        for instance in instances:
            for node in instance[0].members():
                pm.delete(pm.cluster(node)) 
Example #11
Source File: sqCopyPasteShapes.py    From dpAutoRigSystem with GNU General Public License v2.0 6 votes vote down vote up
def hold_ctrl_shapes(ctrl, parent=None):
    """
    Make a snapshot of all shapes of a specific ctrls.
    """
    shapes = filter(lambda x: isinstance(x, pymel.nodetypes.CurveShape), ctrl.getShapes())
    snapshot_transform = pymel.duplicate(ctrl, parentOnly=True, returnRootsOnly=True)[0]
    for shape in shapes:
        shape_snapshot = _duplicate_shape(shape)
        tmp_transform = shape_snapshot.getParent()
        shape_snapshot.setParent(snapshot_transform, s=True, r=True)
        pymel.delete(tmp_transform)
    if parent:
        snapshot_transform.setParent(parent)
    else:
        snapshot_transform.setParent(world=True)
    snapshot_transform.rename('{0}Snapshot'.format(ctrl.name()))
    return snapshot_transform 
Example #12
Source File: benchmark.py    From tutorials with MIT License 6 votes vote down vote up
def testPyCmds():

    start = time.time()

    helix = cmds.polyHelix(**HELIX_OPTS)
    pHelix = helix[0]

    size = cmds.polyEvaluate(v=True)

    for i in xrange(size):
        x = RAND.uniform(LOW, HIGH)
        attrib = '%s.vtx[%s]' % (pHelix, i)
        cmds.move(x, attrib, x=True)
    
    cmds.delete(pHelix)

    end = time.time()
    return end-start 
Example #13
Source File: benchmark.py    From tutorials with MIT License 6 votes vote down vote up
def testPyMel():

    start = time.time()

    helix = pm.polyHelix(**HELIX_OPTS)
    pHelix = helix[0]

    # 20020 loops
    for v in pHelix.vtx:

        # strangly, its faster to make a new vector
        # object every time, as opposed to creating it
        # once and changing the x value each time???
        vector = pm.dt.Vector(x=RAND.uniform(LOW, HIGH))
        v.translateBy(vector)
    
    pm.delete(pHelix)

    end = time.time()
    return end-start 
Example #14
Source File: dpPoseReader.py    From dpAutoRigSystem with GNU General Public License v2.0 6 votes vote down vote up
def populateData(self):
        lstNetworkNode = libSerialization.getNetworksByClass(PoseReaderData.__name__)
        aToDel = []
        for pNet in lstNetworkNode:
            pData = libSerialization.import_network(pNet)
            #Ensure that the network is valid, if not, delete the network node
            for sVar in pData.__dict__ :
                #print "{0} --> {1}".format(sVar, pData.__dict__[sVar])
                if not (pData.__dict__[sVar]): #TODO --> Delete invalid system node ?
                    aToDel.append(pNet)
                    break;
            if not aToDel: self.addItem(pData)

        if aToDel:
            pymel.delete(aToDel)

    #We could use the function pymel.spaceLocator() :P 
Example #15
Source File: lightManager2016Below.py    From PythonForMayaSamples with GNU General Public License v3.0 6 votes vote down vote up
def getDock(name='LightingManagerDock'):
    """
    This function creates a dock with the given name.
    It's an example of how we can mix Maya's UI elements with Qt elements
    Args:
        name: The name of the dock to create

    Returns:
        QtWidget.QWidget: The dock's widget
    """
    # First lets delete any conflicting docks
    deleteDock(name)
    # Then we create a dockControl dock using Maya's UI tools
    # This gives us back the name of the dock created
    
    # <=Maya2016: In Maya 2016 and below, we just give our Light Managers object name to the dockControl.
    # You can see this name when we do self.setObjectName in the LightManagers __init__ method
    ctrl = pm.dockControl(name, area='right', content='lightingManager', allowedArea='all', label="Lighting Manager")

    # And then we return the control name
    return ctrl 
Example #16
Source File: general.py    From anima with MIT License 6 votes vote down vote up
def delete_unused_intermediate_shapes(cls):
        """clears unused intermediate shape nodes
        """
        ignored_node_types = [
            'nodeGraphEditorInfo',
            'shadingEngine',
        ]

        def filter_funct(x):
            return x.type() not in ignored_node_types

        unused_nodes = []
        for node in pm.ls(type=pm.nt.Mesh):
            if len(filter(filter_funct, node.inputs())) == 0 and \
               len(filter(filter_funct, node.outputs())) == 0 \
               and node.attr('intermediateObject').get():
                unused_nodes.append(node)
        pm.delete(unused_nodes) 
Example #17
Source File: sqSpaceSwitcher.py    From dpAutoRigSystem with GNU General Public License v2.0 6 votes vote down vote up
def _update_lstParent(self, pSpData):
        """
        Update the parent list for the selected system
        """
        self.createModel.clear()
        if pSpData:
            self.ui.lstParent.setEnabled(True)
            self.createModel.appendRow(self.parentItem)
            for iIdx, nParentInfo in enumerate(pSpData.aDrivers):
                newParentItem = QtGui.QStandardItem(nParentInfo.name())
                newParentItem.setEditable(False)
                # Prevent any delete action when the sysem is referenced
                if pymel.referenceQuery(self.pSelSpSys.nSwConst, isNodeReferenced=True):
                    newParentItem.setCheckable(False)
                else:
                    newParentItem.setCheckable(True)
                self.createModel.appendRow(newParentItem)
        else:
            self.ui.lstParent.setEnabled(False)
            self.createModel.appendRow(self.parentItem) 
Example #18
Source File: sqSpaceSwitcher.py    From dpAutoRigSystem with GNU General Public License v2.0 6 votes vote down vote up
def _fetch_system_from_scene(self):
        """
        Get all SpaceSwitch system in the scene
        """
        self.aSceneSpaceSwitch = []
        self.ui.cbSysList.clear()
        self.ui.cbSysList.addItem("--- Select a system ---")

        lstNetworkNode = libSerialization.getNetworksByClass(SpaceSwitcherLogic.__name__)
        for pNet in lstNetworkNode:
            pData = libSerialization.import_network(pNet)
            # Check to ensure the data is valid, delete it if not
            if pData.nDriven is not None and pData.nSwConst is not None and pData.nSwConstRecept is not None:
                self.ui.cbSysList.addItem(pData.nDriven.name())
                self.aSceneSpaceSwitch.append(pData)
            else:
                print("System {0} will be deleted because some data is invalid. Driven = {1}, Const = {2}, "
                      "Const Recept = {3}".format(pNet, pData.nDriven, pData.nSwConst, pData.nSwConstRecept))
                pymel.delete(pNet) 
Example #19
Source File: previs.py    From anima with MIT License 5 votes vote down vote up
def split_camera(cls):
        """splits one camera to multiple cameras
        """
        selection = pm.ls(sl=1, type=pm.nt.Transform)
        if not selection:
            raise RuntimeError("Please select at least one camera")

        new_cameras = []

        from anima.env.mayaEnv import camera_tools
        for cam in selection:
            cut_info = camera_tools.find_cut_info(cam)

            for cut_in, cut_out in cut_info:
                print(cut_in, cut_out)
                # duplicate the original camera with input graph
                dup_cam = pm.duplicate(cam, un=1)[0]

                # remove all keyframes out of the cut range
                # remove befor
                pm.cutKey(dup_cam, time=(-1000, cut_in - 1))
                # # remove after
                pm.cutKey(dup_cam, time=(cut_out + 1, 100000))

                # rename the new cam
                dup_cam.rename("%s_#" % cam.name())

                new_cameras.append(dup_cam)

            # remove original camera
            pm.delete(cam)

        # select all new cameras
        pm.select(new_cameras) 
Example #20
Source File: publish.py    From anima with MIT License 5 votes vote down vote up
def check_lights(progress_controller=None):
    """No lights in the scene

    checks if there are lights in the scene
    """
    if progress_controller is None:
        progress_controller = ProgressControllerBase()
    progress_controller.maximum = 2

    all_lights = pm.ls(
        type=['light', 'aiAreaLight', 'aiSkyDomeLight', 'aiPhotometricLight',
              'RedshiftPhysicalSun', 'RedshiftPhysicalLight', 'RedshiftIESLight',
              'RedshiftPortalLight', 'RedshiftDomeLight']
    )
    progress_controller.increment()

    if len(all_lights):
        pm.select(all_lights)
        progress_controller.increment()
        progress_controller.complete()
        raise PublishError(
            'There are <b>Lights</b> in the current scene:<br><br>%s<br><br>'
            'Please delete them!!!' %
            '<br>'.join(map(lambda x: x.name(), all_lights))
        )
    progress_controller.complete() 
Example #21
Source File: drawNode.py    From anima with MIT License 5 votes vote down vote up
def temp_inputOrient(self, target, maintainOff=1):
        tempConst = self.inputPoint(target, maintainOff)
        pm.delete(tempConst) 
Example #22
Source File: animation.py    From anima with MIT License 5 votes vote down vote up
def delete_base_anim_layer(cls):
        """deletes the base anim layer
        """
        base_layer = pm.PyNode('BaseAnimation')
        base_layer.unlock()
        pm.delete(base_layer) 
Example #23
Source File: modeling.py    From anima with MIT License 5 votes vote down vote up
def delete_smooth_on_selected(cls):
        selection = pm.ls(sl=1)
        deleteList = []
        for item in selection:
            hist = pm.listHistory(item)
            for i in range(0, len(hist)):
                if hist[i].type() == 'polySmoothFace':
                    deleteList.append(hist[i])
        pm.delete(deleteList) 
Example #24
Source File: modeling.py    From anima with MIT License 5 votes vote down vote up
def delete_smooth(cls):
        Modeling.activate_deActivate_smooth(0)
        selection = pm.ls(type='polySmoothFace')
        if len(selection) > 0:
            pm.delete(selection) 
Example #25
Source File: modeling.py    From anima with MIT License 5 votes vote down vote up
def fix_normals(cls):
        selection = pm.ls(sl=1)
        pm.polySetToFaceNormal()
        for item in selection:
            pm.polyNormal(item, normalMode=2, userNormalMode=0, ch=1)
            pm.polySoftEdge(item, a=30, ch=1)
        pm.delete(ch=1)
        pm.select(selection) 
Example #26
Source File: modeling.py    From anima with MIT License 5 votes vote down vote up
def reverse_normals(cls):
        selection = pm.ls(sl=1)
        for item in selection:
            pm.polyNormal(item, normalMode=0, userNormalMode=0, ch=1)
        pm.delete(ch=1)
        pm.select(selection) 
Example #27
Source File: modeling.py    From anima with MIT License 5 votes vote down vote up
def fix_uvsets(cls):
        """Fixes uvSets (DiffuseUV -> map1)
        """
        for node in pm.selected():
            shape = node.getShape()

            # get current uvset
            uvset_names = pm.polyUVSet(shape, query=True, allUVSets=True)

            if 'DiffuseUV' in uvset_names:
                if len(uvset_names) == 1:
                    # Copy values of uvset "DiffuseUV" to "map1"
                    pm.polyUVSet(shape, copy=True, nuv='map1', uvSet='DiffuseUV')

                    # set current uvset to map1
                    pm.polyUVSet(shape, currentUVSet=True, uvSet='map1')

                    # delete uv set
                    # pm.polyUVSet( shape, delete=True, uvSet='DiffuseUV')
                else:
                    if 'map1' in uvset_names:
                        # set current uvset to map1
                        uvs = shape.getUVs(uvSet='map1')

                        if len(uvs[0]) == 0:
                            # Copy values of uvset "DiffuseUV" to "map1"
                            pm.polyUVSet(shape, copy=True, nuv='map1', uvSet='DiffuseUV') 
Example #28
Source File: picker.py    From anima with MIT License 5 votes vote down vote up
def fix_jump(self):
        """fixes the jump in current frame
        """
        if not self._is_setup: return

        # delete the current parent key and set it again
        parent = self.get_active_parent()

        # remove the parent key at the current frame
        self.delete_current_parent_key()

        # and set the active parent again
        self.set_active_parent(parent) 
Example #29
Source File: selection_manager.py    From anima with MIT License 5 votes vote down vote up
def delete_button(self):
        """delete rows
        """
        pm.deleteUI(self.layout, layout=True) 
Example #30
Source File: selection_manager.py    From anima with MIT License 5 votes vote down vote up
def update(self):
        """updates the storedSelList with the selection from maya
        """
        self.__storedSelList__ = pm.ls(sl=1)
        if self.__selectionSet__:
            pm.delete(self.__selectionSet__)
            self.save()