Python maya.cmds.delete() Examples
The following are 30
code examples of maya.cmds.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
maya.cmds
, or try the search function
.
Example #1
Source File: publish.py From anima with MIT License | 7 votes |
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: dpUtils.py From dpAutoRigSystem with GNU General Public License v2.0 | 6 votes |
def clearNodeGrp(nodeGrpName='dpAR_GuideMirror_Grp', attrFind='guideBaseMirror', unparent=False): """ Check if there is any node with the attribute attrFind in the nodeGrpName and then unparent its children and delete it. """ if cmds.objExists(nodeGrpName): foundChildrenList = [] childrenList = cmds.listRelatives(nodeGrpName, children=True, type="transform") if childrenList: for child in childrenList: if cmds.objExists(child+"."+attrFind) and cmds.getAttr(child+"."+attrFind) == 1: foundChildrenList.append(child) if len(foundChildrenList) != 0: if unparent: for item in foundChildrenList: cmds.parent(item, world=True) cmds.delete(nodeGrpName) else: cmds.delete(nodeGrpName)
Example #3
Source File: freeze.py From SISideBar with MIT License | 6 votes |
def freezeModeling(node, engine='maya'): #子供のノード退避用ダミーペアレントを用意 dummy = common.TemporaryReparent().main(mode='create') common.TemporaryReparent().main(node,dummyParent=dummy, mode='cut') #ヒストリを全削除 cmds.bakePartialHistory(node,pc=True) #ウェイトを書き戻してくる weight.WeightCopyPaste().main(node, mode='paste', saveName=__name__, engine=engine) #いらないシェイプを消す deleteZeroShape(node) #親子付けを戻す common.TemporaryReparent().main(node, dummyParent=dummy, mode='parent') #ダミーペアレントを削除 common.TemporaryReparent().main(dummyParent=dummy, mode='delete') #接続の無い不要なシェイプを削除
Example #4
Source File: mayaSphere4.py From tutorials with MIT License | 6 votes |
def __del__(self): """ This is just an interesting example of built-in methods of python objects. Normally you wouldn't use __del__ like this to delete the maya geometry when the python object is deleted, but it shows a visual representation of python cleaning up its data. Notice what happens when you do this: s = MayaSphere(name="FirstSphere") s.setScale(2,2,2) s = MayaSphere(name="SecondSphere") The FirstSphere is deleted and replaced with SecondSphere, because the variable was overwritten and __del__ was called on the first object after reassigning. """ self.delete()
Example #5
Source File: benchmark.py From tutorials with MIT License | 6 votes |
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 #6
Source File: benchmark.py From tutorials with MIT License | 6 votes |
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 #7
Source File: freeze.py From SISideBar with MIT License | 6 votes |
def freeze(): cmds.selectMode(o=True) selection = cmds.ls(sl=True, type = 'transform') dummy = common.TemporaryReparent().main(mode='create')#モジュールでダミーの親作成 clusterCopy = modeling.ClusterCopy() for sel in selection: allChildren = [sel] + cmds.listRelatives(sel, ad=True)#子供を取得して1つのリストにする polyMesh = common.search_polygon_mesh(allChildren) if polyMesh: for mesh in polyMesh: common.TemporaryReparent().main(mesh, dummyParent=dummy, mode='cut') defCls = clusterCopy.copy(mesh) cmds.bakePartialHistory(mesh,pc=True) if defCls: clusterCopy.paste(mesh) common.TemporaryReparent().main(mesh, dummyParent=dummy, mode='parent')#コピーのおわったメッシュの子供を元に戻す common.TemporaryReparent().main(dummyParent=dummy, mode='delete')#ダミー親削除 cmds.select(selection, r=True)
Example #8
Source File: BlendTransforms.py From BlendTransforms with The Unlicense | 6 votes |
def BT_ConnectSetup(set = None): if not set or not cmds.objExists(set): return False if BT_IsSetupConnected(set = set): cmds.warning('Setup already connected!') return False btNode = cmds.getAttr(set +'.Blend_Node') if not btNode or not cmds.objExists(btNode): return False transforms = cmds.listConnections(set +'.dagSetMembers') for i in range(0, len(transforms)): try: BT_ConnectOutputs(index = i, node = btNode, transform = transforms[i]) except: pass mults = cmds.listConnections(btNode, d = True, type = 'multiplyDivide') if mults: cmds.delete(mults) return True
Example #9
Source File: BlendTransforms.py From BlendTransforms with The Unlicense | 6 votes |
def BT_ConnectSetup(set = None): if not set or not cmds.objExists(set): return False if BT_IsSetupConnected(set = set): cmds.warning('Setup already connected!') return False btNode = cmds.getAttr(set +'.Blend_Node') if not btNode or not cmds.objExists(btNode): return False transforms = cmds.listConnections(set +'.dagSetMembers') for i in range(0, len(transforms)): try: BT_ConnectOutputs(index = i, node = btNode, transform = transforms[i]) except: pass mults = cmds.listConnections(btNode, d = True, type = 'multiplyDivide') if mults: cmds.delete(mults) return True
Example #10
Source File: transform.py From SISideBar with MIT License | 6 votes |
def move_center_each_object(): object_mode = cmds.selectMode( q=True, o=True ) cmds.selectMode(o=True) selection = cmds.ls(sl=True, l=True) meshes = common.search_polygon_mesh(selection, fullPath=True, nurbs=True) if not meshes: return dummy = common.TemporaryReparent().main(mode='create') for m in meshes: cmds.selectMode(o=True) common.TemporaryReparent().main(m, dummyParent=dummy, mode='cut') cmds.select(m, r=True) if not object_mode: cmds.selectMode(co=True) move_center2selection() common.TemporaryReparent().main(m, dummyParent=dummy, mode='parent') common.TemporaryReparent().main(dummyParent=dummy, mode='delete') freeze.main(mesh=selection) cmds.select(selection, r=True)
Example #11
Source File: manager.py From spore with MIT License | 6 votes |
def context_request(self, widget, action): if action.text() == 'Delete': selection = cmds.ls(sl=1, typ='sporeNode') for geo_wdg, spore_wdgs in self.wdg_tree.iteritems(): for spore_wdg in spore_wdgs: spore_node = spore_wdg.name print spore_node if spore_wdg.is_selected and cmds.objExists(spore_node): instancer = node_utils.get_instancer(spore_node) transform = cmds.listRelatives(spore_node, p=True, f=True) if len(cmds.listRelatives(transform, c=1)) == 1: cmds.delete((spore_node, transform[0], instancer)) else: cmds.delete((spore_node, instancer)) selection.remove(spore_node) cmds.select(selection) self.refresh_spore()
Example #12
Source File: BlendTransforms.py From BlendTransforms with The Unlicense | 6 votes |
def BT_ConnectSetup(set = None): if not set or not cmds.objExists(set): return False if BT_IsSetupConnected(set = set): cmds.warning('Setup already connected!') return False btNode = cmds.getAttr(set +'.Blend_Node') if not btNode or not cmds.objExists(btNode): return False transforms = cmds.listConnections(set +'.dagSetMembers') for i in range(0, len(transforms)): try: BT_ConnectOutputs(index = i, node = btNode, transform = transforms[i]) except: pass mults = cmds.listConnections(btNode, d = True, type = 'multiplyDivide') if mults: cmds.delete(mults) return True
Example #13
Source File: BlendTransforms.py From BlendTransforms with The Unlicense | 6 votes |
def BT_ConnectSetup(set = None): if not set or not cmds.objExists(set): return False if BT_IsSetupConnected(set = set): cmds.warning('Setup already connected!') return False btNode = cmds.getAttr(set +'.Blend_Node') if not btNode or not cmds.objExists(btNode): return False transforms = cmds.listConnections(set +'.dagSetMembers') for i in range(0, len(transforms)): try: BT_ConnectOutputs(index = i, node = btNode, transform = transforms[i]) except: pass mults = cmds.listConnections(btNode, d = True, type = 'multiplyDivide') if mults: cmds.delete(mults) return True
Example #14
Source File: orientjoints.py From cmt with MIT License | 6 votes |
def align_with_child(joints): """Aligns the up axis of the given joints with their respective child joint. @param joints: List of joints to orient. """ for joint in joints: children = _unparent_children(joint) if children: cmds.delete( cmds.aimConstraint( children[0], joint, aim=(1, 0, 0), upVector=(0, 1, 0), worldUpType="objectrotation", worldUpVector=(0, 1, 0), worldUpObject=children[0], ) ) cmds.makeIdentity(joint, apply=True) _reparent_children(joint, children) if joints: cmds.select(joints)
Example #15
Source File: cmdx.py From cmdx with BSD 2-Clause "Simplified" License | 6 votes |
def pop(self, key): """Delete an attribute Arguments: key (str): Name of attribute to delete Example: >>> node = createNode("transform") >>> node["myAttr"] = Double() >>> node.pop("myAttr") >>> node.hasAttr("myAttr") False """ del self[key]
Example #16
Source File: shapesui.py From cmt with MIT License | 6 votes |
def import_selected_objs(self, add_as_targets=True): """Import the selected shapes in the tree view. If a mesh with a blendshape is selected in the scene, the shapes will be added as targets """ indices = self.file_tree_view.selectedIndexes() if not indices: return None paths = self.get_selected_paths() sel = cmds.ls(sl=True) blendshape = bs.get_blendshape_node(sel[0]) if sel else None meshes = [import_obj(path) for path in paths] if blendshape and add_as_targets: for mesh in meshes: bs.add_target(blendshape, mesh) cmds.delete(mesh) elif meshes: cmds.select(meshes) return meshes
Example #17
Source File: cmdx.py From cmdx with BSD 2-Clause "Simplified" License | 6 votes |
def exists(self): """The node exists in both memory *and* scene Example: >>> node = createNode("joint") >>> node.exists True >>> cmds.delete(str(node)) >>> node.exists False >>> node.destroyed False >>> _ = cmds.file(new=True, force=True) >>> node.exists False >>> node.destroyed True """ return not self._removed
Example #18
Source File: dpEye.py From dpAutoRigSystem with GNU General Public License v2.0 | 6 votes |
def createEyelidJoints(self, side, lid, middle, cvEyelidLoc, jointLabelNumber, *args): ''' Create the eyelid joints to be used in the needed setup. Returns EyelidBaseJxt and EyelidJnt created for rotate and skinning. ''' # declating a concatenated name used for base to compose: baseName = side+self.userGuideName+"_"+self.langDic[self.langName][lid]+"_"+self.langDic[self.langName]['c042_eyelid']+middle # creating joints: eyelidBaseZeroJxt = cmds.joint(name=baseName+"_Base_Zero_Jxt", rotationOrder="yzx", scaleCompensate=False) eyelidBaseJxt = cmds.joint(name=baseName+"_Base_Jxt", rotationOrder="yzx", scaleCompensate=False) eyelidZeroJxt = cmds.joint(name=baseName+"_Zero_Jxt", rotationOrder="yzx", scaleCompensate=False) eyelidJnt = cmds.joint(name=baseName+"_Jnt", rotationOrder="yzx", scaleCompensate=False) cmds.addAttr(eyelidJnt, longName='dpAR_joint', attributeType='float', keyable=False) utils.setJointLabel(eyelidJnt, jointLabelNumber, 18, self.userGuideName+"_"+self.langDic[self.langName][lid]+"_"+self.langDic[self.langName]['c042_eyelid']+middle) cmds.select(eyelidZeroJxt) eyelidSupportJxt = cmds.joint(name=baseName+"_Jxt", rotationOrder="yzx", scaleCompensate=False) cmds.setAttr(eyelidSupportJxt+".translateX", self.ctrlRadius*0.1) # positioning and orienting correctely eyelid joints: cmds.delete(cmds.aimConstraint(cvEyelidLoc, eyelidBaseZeroJxt, aimVector=(0,0,1), worldUpType="objectrotation", worldUpObject=self.eyelidJxt)) cmds.delete(cmds.parentConstraint(cvEyelidLoc, eyelidZeroJxt, mo=False)) cmds.setAttr(eyelidZeroJxt+".rotateX", 0) cmds.setAttr(eyelidZeroJxt+".rotateY", 0) cmds.setAttr(eyelidZeroJxt+".rotateZ", 0) cmds.select(self.eyelidJxt) return eyelidBaseJxt, eyelidJnt
Example #19
Source File: s01_d023_retrievingContainedObjects.py From didactic with BSD 3-Clause "New" or "Revised" License | 6 votes |
def deleteGuideHierarchyFromKeyObjects(keyObs): """ :param keyObs: `dict` key objects in a pre-canned dictionary as informed by keyObjectsFromContainer :return: `bool` True if the guide was found and deleted, False if one wasn't found """ hasBeenDeleted = False if keyObs['guide'] is not None: dagPathToGuide = om2.MDagPath.getAPathTo(keyObs['guide'].object()).fullPathName() m_cmds.delete(dagPathToGuide) hasBeenDeleted = True return hasBeenDeleted # main
Example #20
Source File: s01_d025_swappingPlugs.py From didactic with BSD 3-Clause "New" or "Revised" License | 6 votes |
def deleteGuideHierarchyFromKeyObjects(keyObs): """ :param keyObs: `dict` key objects in a pre-canned dictionary as informed by keyObjectsFromContainer :return: `bool` True if the guide was found and deleted, False if one wasn't found """ hasBeenDeleted = False if keyObs['guide'] is not None: dagPathToGuide = om2.MDagPath.getAPathTo(keyObs['guide'].object()).fullPathName() m_cmds.delete(dagPathToGuide) hasBeenDeleted = True return hasBeenDeleted # main
Example #21
Source File: uExport.py From uExport with zlib License | 6 votes |
def convertSkelSettingsToNN(delete=1): orig = 'SkeletonSettings_Cache' if cmds.objExists(orig): if cmds.nodeType(orig) == 'unknown': new = cmds.createNode('network') for att in cmds.listAttr(orig): if not cmds.attributeQuery(att, node=new, exists=1): typ = cmds.attributeQuery(att, node=orig, at=1) if typ == 'typed': cmds.addAttr(new, longName=att, dt='string') if cmds.getAttr(orig + '.' + att): cmds.setAttr(new + '.' + att, cmds.getAttr(orig + '.' + att), type='string') elif typ == 'enum': cmds.addAttr(new, longName=att, at='enum', enumName=cmds.attributeQuery(att, node=orig, listEnum=1)[0]) cmds.delete(orig) cmds.rename(new, 'SkeletonSettings_Cache')
Example #22
Source File: dpBaseControlClass.py From dpAutoRigSystem with GNU General Public License v2.0 | 6 votes |
def doControlAction(self, destinationList, *args): """ Action to do when creating a control Do action as user wants: 1 = New control 2 = Add shape 3 = Replace shapes """ if self.cvAction == 1: #new control pass else: if destinationList: if self.cvAction == 2: #add shape self.ctrls.transferShape(True, False, self.cvCurve, destinationList, True) elif self.cvAction == 3: #replace shapes self.ctrls.transferShape(True, True, self.cvCurve, destinationList, True) else: cmds.delete(self.cvCurve) mel.eval("warning \""+self.langDic[self.langName]['e011_notSelShape']+"\";")
Example #23
Source File: control.py From cmt with MIT License | 5 votes |
def create(self, transform=None, as_controller=True): """Create a curve. :param transform: Name of the transform to create the curve shape under. If the transform does not exist, it will be created. :param as_controller: True to mark the curve transform as a controller. :return: The transform of the new curve shapes. """ transform = transform or self.transform if not cmds.objExists(transform): transform = cmds.createNode("transform", name=transform) periodic = self.form == 2 points = self._get_transformed_points() points = points + points[: self.degree] if periodic else points curve = cmds.curve(degree=self.degree, p=points, per=periodic, k=self.knots) shape = shortcuts.get_shape(curve) if self.color is not None: cmds.setAttr("{}.overrideEnabled".format(shape), True) if isinstance(self.color, int): cmds.setAttr("{}.overrideColor".format(shape), self.color) else: cmds.setAttr("{}.overrideRGBColors".format(shape), True) cmds.setAttr("{}.overrideColorRGB".format(shape), *self.color) cmds.parent(shape, transform, r=True, s=True) shape = cmds.rename(shape, "{}Shape".format(transform)) cmds.delete(curve) if as_controller: cmds.controller(transform) logger.info("Created curve {} for transform {}".format(shape, transform)) return transform
Example #24
Source File: publish.py From anima with MIT License | 5 votes |
def delete_unknown_nodes(progress_controller=None): """Delete unknown nodes :param progress_controller: It is an object to inform the progress. """ # delete the unknown nodes if progress_controller is None: progress_controller = ProgressControllerBase() progress_controller.minimum = 0 progress_controller.value = 0 unknown_nodes = mc.ls(type='unknown') progress_controller.maximum = len(unknown_nodes) # unlock each possible locked unknown nodes for node in enumerate(unknown_nodes): try: mc.lockNode(node, lock=False) except TypeError: pass progress_controller.increment() if unknown_nodes: mc.delete(unknown_nodes) progress_controller.complete()
Example #25
Source File: test_cmt_control.py From cmt with MIT License | 5 votes |
def test_save_and_load_curves(self): file_path = self.get_temp_filename("test_curve.json") control.export_curves([self.curve], file_path) self.assertTrue(os.path.exists(file_path)) cmds.delete(self.curve) controls = control.import_curves(file_path) self.assertTrue(cmds.objExists(self.curve)) self.assertEqual(controls[0], self.curve) self.test_get_curve_object()
Example #26
Source File: mayaSphere4.py From tutorials with MIT License | 5 votes |
def delete(self): if self.exists(): cmds.delete(self.name)
Example #27
Source File: cmdx.py From cmdx with BSD 2-Clause "Simplified" License | 5 votes |
def delete(*nodes): with DGModifier() as mod: for node in nodes: mod.delete(node)
Example #28
Source File: cmdx.py From cmdx with BSD 2-Clause "Simplified" License | 5 votes |
def __add__(self, other): """Support legacy + '.attr' behavior Example: >>> node = createNode("transform") >>> getAttr(node + ".tx") 0.0 >>> delete(node) """ return self[other.strip(".")]
Example #29
Source File: boundCollection.py From mGui with MIT License | 5 votes |
def do_delete(self, *args, **kwargs): template = kwargs['sender'].tag original = template.tag name_field = template.filler.name_field obj = name_field.object cmds.delete(obj) self.collection.remove(original)
Example #30
Source File: anyLayer.py From medic with MIT License | 5 votes |
def fix(self, report, params): node = report.node() if node.dg().isFromReferencedFile(): return False if node.dg().isLocked(): node.dg().setLocked(False) cmds.delete(node.name()) return True