Python源码示例:pymel.core.objExists()
示例1
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
示例2
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
示例3
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 )
示例4
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))
示例5
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
示例6
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)
示例7
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
示例8
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
示例9
def pruneUnused():
if not objExists('|main'):
return
shape = get()
groups = existingGroups()
for g in groups:
attr = shape + '.' + g
if not listConnections(attr):
deleteAttr(attr)
示例10
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)
示例11
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
示例12
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
示例13
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()
示例14
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)
示例15
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