Python pymel.core.objExists() Examples
The following are 15
code examples of pymel.core.objExists().
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: auxiliary.py From anima with MIT License | 6 votes |
def create_arnold_stand_in(path=None): """A fixed version of original arnold script of SolidAngle Arnold core API """ if not pm.objExists('ArnoldStandInDefaultLightSet'): pm.createNode( "objectSet", name="ArnoldStandInDefaultLightSet", shared=True ) pm.lightlink( object='ArnoldStandInDefaultLightSet', light='defaultLightSet' ) stand_in = pm.createNode('aiStandIn', n='ArnoldStandInShape') # temp fix until we can correct in c++ plugin stand_in.setAttr('visibleInReflections', True) stand_in.setAttr('visibleInRefractions', True) pm.sets('ArnoldStandInDefaultLightSet', add=stand_in) if path: stand_in.setAttr('dso', path) return stand_in
Example #2
Source File: manager.py From metanode with BSD 3-Clause "New" or "Revised" License | 6 votes |
def update_metanodes(cls): """ Call .update() on all metanodes in cls.update and return update messages. """ update_message = '' for metanode in reversed(cls.update): cls.update.remove(metanode) if pm.objExists(metanode.node): cls.network_nodes.remove(metanode.node) new, missing, could_not_set = metanode.update() if new: cls.network_nodes.append(new.node) update_message += 'Updating Metanode: {0}\n'.format(new) if missing: update_message += 'New Metanode lacks previous attributes: {0}'.format(missing) if could_not_set: update_message += 'Could not set attributes: {0}'.format(could_not_set) return update_message # DEPRECATED
Example #3
Source File: anim.py From fossil with BSD 3-Clause "New" or "Revised" License | 6 votes |
def _processAttr(plug, dups, forceKeys, staticValues, start, end): ''' Used by `save` ''' crvs = cmds.listConnections( plug, type='animCurve' ) if not crvs: if forceKeys: setKeyframe( plug, t=start ) setKeyframe( plug, t=end ) crvs = cmds.listConnections( plug, type='animCurve' ) else: if not cmds.getAttr(plug, lock=True) and not cmds.listConnections(plug, s=True, d=False): staticValues[plug] = cmds.getAttr(plug) if crvs: dup = cmds.duplicate(crvs)[0] if not objExists(dup + '.' + TAGGING_ATTR): cmds.addAttr( dup, ln=TAGGING_ATTR, dt='string' ) cmds.setAttr( dup + '.' + TAGGING_ATTR, plug, type='string' ) dups.append( dup )
Example #4
Source File: sqCopyPasteShapes.py From dpAutoRigSystem with GNU General Public License v2.0 | 5 votes |
def fetch_all_ctrls_shapes(): """ Restore the snapshots of all shapes of all ctrls. """ aSources = get_all_ctrlsnapshots() for oSource in aSources: sTargetName = oSource.name()[:-8] if pymel.objExists(sTargetName): oTarget = pymel.PyNode(str(sTargetName)) fetch_ctrl_shapes(oSource, oTarget) #pymel.delete(oSource) else: pymel.warning("Can't find {0}".format(sTargetName))
Example #5
Source File: anim_utils.py From mgear_core with MIT License | 5 votes |
def getRootNode(): """Returns the root node from a selected node Returns: PyNode: The root top node """ root = None current = pm.ls(sl=True) if not current: raise RuntimeError("You need to select at least one rig node") if pm.objExists("{}.is_rig".format(current[0])): root = current[0] else: holder = current[0] while pm.listRelatives(holder, parent=True) and not root: if pm.objExists("{}.is_rig".format(holder)): root = holder else: holder = pm.listRelatives(holder, parent=True)[0] if not root: raise RuntimeError("Couldn't find root node from your selection") return root
Example #6
Source File: mayautils.py From DynRigBuilder with MIT License | 5 votes |
def addBreakLine(ctrl, contentString): """ add a breakline to object's channelbox, usually for ctrlers :param ctrl: `PyNode` object to add breakline to :param contentString: `string` breakline content :return: """ attrName = "_" while pm.objExists("{0}.{1}".format(ctrl.name(), attrName)): attrName = attrName + "_" pm.addAttr(ctrl, ln=attrName, at="enum", en=contentString) pm.setAttr("{0}.{1}".format(ctrl.name(), attrName), e=1, channelBox=1)
Example #7
Source File: core.py From metanode with BSD 3-Clause "New" or "Revised" License | 5 votes |
def instance(cls): """ Controls access to the metanode type by returning one common instance of the node """ nodes = cls.scene_metanodes() if nodes: if pm.objExists(cls.__name__): metanode = cls(pm.PyNode(cls.__name__)) else: metanode = nodes[0] else: metanode = cls.create(cls.__name__) return metanode
Example #8
Source File: sharedShape.py From fossil with BSD 3-Clause "New" or "Revised" License | 5 votes |
def find(obj): ''' If there is a shared shape, returns it. If not, returns None. ''' shapes = cmds.listRelatives(obj.name(), type='nurbsCurve', f=True) if not shapes: return None for shape in shapes: if objExists( shape + '.sharedShape' ): return shape return None
Example #9
Source File: sharedShape.py From fossil with BSD 3-Clause "New" or "Revised" License | 5 votes |
def pruneUnused(): if not objExists('|main'): return shape = get() groups = existingGroups() for g in groups: attr = shape + '.' + g if not listConnections(attr): deleteAttr(attr)
Example #10
Source File: sharedShape.py From fossil with BSD 3-Clause "New" or "Revised" License | 5 votes |
def deserializeAllConnections(connections=None): if connections is None: connections = json.loads( core.text.clipboard.get() ) for obj, data in connections.items(): if objExists(obj): connect(PyNode(obj), data)
Example #11
Source File: findNode.py From fossil with BSD 3-Clause "New" or "Revised" License | 5 votes |
def getRoot(nodes=None, make=None): ''' Returns the root bone, trying to account for case and namespaces or None if not found. `make` should be either 'root' or 'weaponRoot', specifying which to make (always top level) if a root is not found. Can be given a list of nodes to search for the root, ''' names = [ 'b_root', 'b_Root', 'Rig:b_root', 'Rig:b_Root', 'b_weaponRoot', 'Rig:b_weaponRoot' ] if not nodes: # Check if any exist top level first top = ls(assemblies=True) for name in names: if name in top: return PyNode('|' + name) # See if there is a top level obj in a namespace named b_root of any casing. searchNodes = nodes if nodes else ls( assemblies=True ) nodes = [obj for obj in searchNodes if simpleName( obj ).lower() == 'b_root' or simpleName(obj).lower() == 'b_weaponroot'] if len(nodes) == 1: return nodes[0] # Then check if any exist at all (which will fail if several exist in separate groups). for name in names: if objExists( name ): return PyNode( name ) if make: return joint(None, n='b_' + make) else: return None
Example #12
Source File: findNode.py From fossil with BSD 3-Clause "New" or "Revised" License | 5 votes |
def mainGroup(nodePool=None): ''' Returns the main group containing the rig, named "main", or an object tagged as the main. todo: This logic should mainly go into `mainControls`, and this just returns the first. ''' if nodePool: for n in nodePool: if simpleName(n) == 'main' or n.hasAttr(MAIN_CONTROL_TAG): return n if objExists('|main'): return PyNode('|main') else: # A pymel bug is sometimes returning duplicate nodes main = list(set([ obj for obj in ls( 'main', r=True) if not obj.getParent() ])) if len(main) == 1: return main[0] # No "main" ojbect was found, looking for tags plugs = ls('*.' + MAIN_CONTROL_TAG) if plugs: return plugs[0].node() return None
Example #13
Source File: test_fossil.py From fossil with BSD 3-Clause "New" or "Revised" License | 5 votes |
def test_basicBiped(): #gui = main.RigTool() # Make the default biped card.bipedSetup(spineCount=5) # Make all the bones and test their existence select(core.findNode.allCards()) main.RigTool.buildBones() for j in jointsToMake: assert objExists(j), 'Joint ' + j + ' was not made' root = core.findNode.getRoot() assert len(listRelatives(root, ad=True, type='joint')) == (len(jointsToMake) - 1), 'Too many bones were made' # Build the rig spine = PyNode('Spine_card') rigData = spine.rigData rigData['rigCmd'] = 'SplineChest' spine.rigData = rigData select(core.findNode.allCards()) main.RigTool.buildRig()
Example #14
Source File: sharedShape.py From fossil with BSD 3-Clause "New" or "Revised" License | 4 votes |
def connect( obj, name_level ): ''' Hook the given obj's visibility to the `name` attribute on the sharedShape. If the attr doesn't exist, it will be made. Optionanal `level` will determine when the `obj` will become visible. For example, 2 will not be visible at 1, but will at 2 and higher. ''' name, level = name_level # Probably should just update this eventually to be 3 params orig = obj zero = core.dagObj.zero(obj, apply=False, make=False) if zero: obj = zero shape = get() if not shape: warning('Unable to add vis control, no object exists named "main" or tagged with ".fossilMainControl"') return log.debug('Applying vis control to {}, was given {} using {}'.format(obj, orig, shape)) plug = shape + '.' + name if not cmds.objExists( plug ): cmds.addAttr( shape, ln=name, at='short', min=0, max=level, dv=1 ) cmds.setAttr( shape + '.' + name, cb=True ) elif cmds.getAttr( shape + '.' + name, type=True) not in ['bool', 'double', 'float', 'long', 'short']: warning( '{0} is not a good name for a vis group since the sharedShape has an attr already that is of the wrong type'.format(name) ) return if cmds.addAttr(plug, q=True, max=True) < level: cmds.addAttr(plug, e=True, max=level) if level == 1: connectAttr( plug, obj.visibility.name(), f=True) else: connectAttr( getConditionNode(plug, level).outColorR, obj.visibility, f=True) obj.visibility.setKeyable(False) # If we have a main controller, put the container in a subgroup to make # the main group more organized. visGroupName = '_vis_' + name if not find(orig): use(orig) if isinstance(orig, nodeApi.RigController): if shortName(orig.container.getParent()) != visGroupName: orig.setGroup(visGroupName)
Example #15
Source File: findNode.py From fossil with BSD 3-Clause "New" or "Revised" License | 4 votes |
def rootMotion(main=None): ''' Returns the root motion, optionally making one if it doesn't exist. If main is specified, search its descendents. ''' ''' Timing test with Swift as main, re and split are about equal and 200x faster! re and split were almost identical, even on the whole scene. s = time.time() #oldGetRootMotion(main) for child in listRelatives(main, ad=True, type='transform'): #for child in ls(type='transform'): if lib.dagObj.simpleName( child ) == 'rootMotion': break #return child print( time.time() - s, 'orig') s = time.time() for child in cmds.listRelatives(main.name(), ad=True, type='transform'): #for child in cmds.ls(type='transform'): if child.rsplit('|',1)[-1].rsplit(':', 1)[-1] == 'rootMotion': #print( child) break print( time.time() - s, 'split') s = time.time() simpleName = re.compile( '\w+$' ) for child in cmds.listRelatives(main.name(), ad=True, type='transform'): #for child in cmds.ls(type='transform'): if simpleName.search(child).group(0) == 'rootMotion': #print( child) break print( time.time() - s, 're') ''' if main: children = cmds.listRelatives(main.name(), ad=True, type='transform') if children: # cmds returns None instead of emtpy list for child in children: if child.rsplit('|', 1)[-1].rsplit(':', 1)[-1] == 'rootMotion': return PyNode(child) return None if objExists( 'rootMotion' ): return PyNode( 'rootMotion' ) else: rms = ls( 'rootMotion', r=True ) if len(rms) == 1: return rms[0] return None