本文整理汇总了Python中maya.cmds.objExists函数的典型用法代码示例。如果您正苦于以下问题:Python objExists函数的具体用法?Python objExists怎么用?Python objExists使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了objExists函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: distributeAttrValue
def distributeAttrValue(targetList,targetAttr,rangeStart=0.0,rangeEnd=1.0,smoothStep=0.0):
'''
Distribute a range of attribute values across list of target objects
@param targetList: List of target objects to distribute the attribute values across
@type targetList: list
@param targetAttr: The target attribute that the distributed values will be applied to
@type targetAttr: str
@param rangeStart: The distribution range minimum value
@type rangeStart: float
@param rangeEnd: The distribution range maximum value
@type rangeEnd: float
@param smoothStep: Amount of value smoothing to apply to the distribution
@type smoothStep: float
'''
# Check target list
for i in range(len(targetList)):
if not mc.objExists(targetList[i]):
raise UserInputError('Object "'+targetList[i]+'" does not exist!')
if not mc.objExists(targetList[i]+'.'+targetAttr):
raise UserInputError('Object "'+targetList[i]+'" has no ".'+targetAttr+'" attribute!')
# Get value list
vList = glTools.utils.mathUtils.distributeValue(len(targetList),1.0,rangeStart,rangeEnd)
# Apply values to target list
for i in range(len(targetList)):
val = vList[i]
if smoothStep: val = glTools.utils.mathUtils.smoothStep(val,rangeStart,rangeEnd,smoothStep)
mc.setAttr(targetList[i]+'.'+targetAttr,val)
示例2: _publish_gpu_for_item
def _publish_gpu_for_item(self, item, output, work_template, primary_publish_path, sg_task, comment, thumbnail_path, progress_cb):
"""
Export a gpu cache for the specified item and publish it to Shotgun.
"""
group_name = item["name"].strip("|")
debug(app = None, method = '_publish_gpu_for_item', message = 'group_name: %s' % group_name, verbose = False)
tank_type = output["tank_type"]
publish_template = output["publish_template"]
# get the current scene path and extract fields from it using the work template:
scene_path = os.path.abspath(cmds.file(query=True, sn= True))
fields = work_template.get_fields(scene_path)
publish_version = fields["version"]
# update fields with the group name:
fields["grp_name"] = group_name
## create the publish path by applying the fields with the publish template:
publish_path = publish_template.apply_fields(fields)
#'@asset_root/publish/gpu/{name}[_{grp_name}].v{version}.abc'
gpuFileName = os.path.splitext(publish_path)[0].split('\\')[-1]
fileDir = '/'.join(publish_path.split('\\')[0:-1])
debug(app = None, method = '_publish_gpu_for_item', message = 'gpuFileName: %s' % gpuFileName, verbose = False)
## Now fix the shaders
shd.fixDGForGPU()
if cmds.objExists('CORE_ARCHIVES_hrc'):
cmds.setAttr('CORE_ARCHIVES_hrc.visiblity', 0)
if cmds.objExists('ROOT_ARCHIVES_DNT_hrc'):
cmds.setAttr('ROOT_ARCHIVES_DNT_hrc.visiblity', 0)
## build and execute the gpu cache export command for this item:
try:
print '====================='
print 'Exporting gpu now to %s\%s' % (fileDir, gpuFileName)
#PUT THE FILE EXPORT COMMAND HERE
cmds.select(clear = True)
for geo in cmds.listRelatives(group_name, children = True):
if 'geo_hrc' in geo:
geoGroup = str(group_name)
debug(app = None, method = '_publish_gpu_for_item', message = 'geoGroup: %s' % geoGroup, verbose = False)
cmds.select(geoGroup)
debug(app = None, method = '_publish_gpu_for_item', message = 'geoGroup: %s' % geoGroup, verbose = False)
debug(app = None, method = '_publish_gpu_for_item', message = "gpuCache -startTime 1 -endTime 1 -optimize -optimizationThreshold 40000 -directory \"%s\" -fileName %s %s;" % (fileDir, gpuFileName, geoGroup), verbose = False)
mel.eval("gpuCache -startTime 1 -endTime 1 -optimize -optimizationThreshold 40000 -directory \"%s\" -fileName %s %s;" % (fileDir, gpuFileName, geoGroup))
print 'Finished gpu export...'
print '====================='
if cmds.objExists('dgSHD'):
## Now reconnect the FileIn nodes
for key, var in filesDict.items():
cmds.connectAttr('%s.outColor' % key, '%s.color' % var)
except Exception, e:
raise TankError("Failed to export gpu cache file")
示例3: unparent
def unparent(shape):
'''
Unparent shape nodes from a source parent
@param shape: Shape or transform to unparent shapes from
@type shape: str
'''
# Checks
if not mc.objExists(shape):
raise Exception('Object "'+shape+'" does not exist!!')
# Get shapes
if mc.ls(shape,type='transform'):
transform = shape
shapes = mc.listRelatives(shape,s=True,pa=True)
else:
transform = mc.listRelatives(shape,p=True,pa=True)[0]
shapes = [shape]
# Create shape holder
shapeHolder = transform+'Shapes'
if not mc.objExists(shapeHolder): shapeHolder = mc.createNode('transform',n=shapeHolder)
targetXform = mc.xform(transform,q=True,ws=True,m=True)
mc.xform(shapeHolder,ws=True,m=targetXform)
# Unparent shapes
for shape in shapes:
mc.parent(shape,shapeHolder,s=True,r=True)
# Return Result
return shapeHolder
示例4: doSyncInfo
def doSyncInfo(self) :
asset = entityInfo.info()
rigGrps = ['Rig_Grp', 'Rig:Rig_Grp']
assetID = self.getAssetID()
attrs = ['assetID', 'assetType', 'assetSubType', 'assetName', 'project']
values = [assetID, asset.type(), asset.subType(), asset.name(), asset.project()]
geoGrps = ['Geo_Grp', 'Rig:Geo_Grp']
refPath = asset.getPath('ref')
pipelineTools.assignGeoInfo()
for rigGrp in rigGrps :
if mc.objExists(rigGrp) :
i = 0
for each in attrs :
attr = '%s.%s' % (rigGrp, each)
if mc.objExists(attr) :
if not each == 'assetID' :
mc.setAttr(attr, values[i], type = 'string')
else :
mc.setAttr(attr, values[i])
i += 1
for geoGrp in geoGrps :
if mc.objExists(geoGrp) :
mc.setAttr('%s.%s' % (geoGrp, 'id'), assetID)
mc.setAttr('%s.%s' % (geoGrp, 'ref'), refPath, type = 'string')
self.setStatus('Sync info', True)
self.messageBox('Information', 'Sync Complete')
示例5: matchUsing
def matchUsing(transform, reference, target):
"""
Match the specified transform to a target transform, relative to a reference transform
@param transform: Transform to set
@type transform: str
@param reference: Reference transform
@type reference: str
@param target: Target transform to match to
@type target: str
"""
# Checks
if not cmds.objExists(transform):
raise Exception('Transform "' + transform + '" does not exist!')
if not cmds.objExists(reference):
raise Exception('Reference transform "' + target + '" does not exist!')
if not cmds.objExists(target):
raise Exception('Target transform "' + target + '" does not exist!')
# Get Transform, Target and Reference Matrices
trMat = getMatrix(transform)
rfMat = getMatrix(reference)
tgMat = getMatrix(target)
# Calculate Transform Target
resultMat = trMat * rfMat.inverse() * tgMat
# Set Transform Matrix
setFromMatrix(transform, resultMat)
示例6: processItems
def processItems(self, sender = None, all = False, case = ''):
cmds.undoInfo(openChunk = True)
cmds.select(clear = True)
if not all:
for eachItem in self._getSelItems():
itemName = eachItem.text().replace(SEP, "|")
if not cmds.objExists(itemName):
itemName = itemName.split("|")[-1] or None
if itemName:
if case == 'select':
cmds.select(itemName, add = True, ne = True)
elif case == 'delete':
cmds.delete(itemName)
elif case == 'deleteCH':
cmds.delete(itemName, ch = True)
else:
count = self.reportTree.count()
items = []
for x in range(count):
if "-----" not in self.reportTree.item(x).text():
itemName = self.reportTree.item(x).text().replace(SEP, "|")
if not cmds.objExists(itemName):
itemName = itemName.split("|")[-1] or None
if itemName:
items.extend([itemName])
if case == 'select':
cmds.select(items, r = True, ne = True)
elif case == 'delete':
cmds.delete(items)
elif case == 'deleteCH':
cmds.delete(items, ch = True)
cmds.undoInfo(closeChunk = True)
示例7: add
def add(self,objectList):
'''
Adds the channel state attr to all specified objects
@param objectList: List of objects to add flags to
@type objectList: list
'''
# Add Channel State Attrs
for obj in objectList:
# Check obj
if not mc.objExists(obj):
raise Exception('Object "'+obj+'" does not exist!')
if not glTools.utils.transform.isTransform(obj):
raise Exception('Object "'+obj+'" is not a valid transform!')
if mc.objExists(obj+'.channelState'):
print ('Object "'+obj+'" already has a "channelState" attribute! Skipping...')
# Add channelState attr
#mc.addAttr(obj,ln='channelState',at='enum',en=':Keyable:NonKeyable:Locked:',m=1,dv=-1)
mc.addAttr(obj,ln='channelState',at='enum',en=':Keyable:NonKeyable:Locked:',m=1)
# Set channelState flag values
for i in range(len(self.channel)):
if mc.getAttr(obj+'.'+self.channel[i],l=1):
# Set Locked State
mc.setAttr(obj+'.channelState['+str(i)+']',2)
elif not mc.getAttr(obj+'.'+self.channel[i],k=1):
# Set NonKeyable State
mc.setAttr(obj+'.channelState['+str(i)+']',1)
else:
# Set Keyable State
mc.setAttr(obj+'.channelState['+str(i)+']',0)
# Alias Attribute
mc.aliasAttr(self.channel[i]+'_state',obj+'.channelState['+str(i)+']')
示例8: doAnimRig
def doAnimRig(self) :
path = str(self.ui.path_lineEdit.text())
texturePath = '%s/textures' % path
animRes = str(self.ui.animRes_comboBox.currentText())
facialCore.path = texturePath
facialCore.animRes = animRes
if mc.objExists(self.renderHeadName) :
previewHead = mc.duplicate(self.renderHeadName, n = self.previewHeadName)[0]
# render node
ltNode = facialCore.makeAnimFacial(facialCore.renderLayerTextureName)
# create lambert
if not mc.objExists(self.animNode) :
mtl = mc.shadingNode('lambert', asShader = True, n = self.animNode)
# connect
mc.connectAttr('%s.outColor' % ltNode, '%s.color' % mtl, f = True)
# assign
mc.select(previewHead)
mc.hyperShade(assign = mtl)
self.messageBox('Success', 'Set Anim Node Complete')
示例9: on_actionStartMove_triggered
def on_actionStartMove_triggered(self, args=None):
if args==None:return
toMoveOBJ = str(self.MovedOBJLineEdit.text())
toKeepOBJ = str(self.KeepedOBJLineEdit.text())
if not mc.objExists(toMoveOBJ) or not mc.objExists(toKeepOBJ):return
if toMoveOBJ == toKeepOBJ:return
self.ConstraintDT = {}
self.ConstraintLocators = []
for Jnt in (toKeepOBJ, toMoveOBJ):
OldConstraintNode = [x for x in mc.listRelatives(Jnt, c=True, path=True) or [] if mc.nodeType(x).endswith('Constraint')]
for OCSN in OldConstraintNode:
ConstraintType = mc.nodeType(OCSN)
ConstraintOBJ = eval('mc.%s("%s", q=True, tl=True)'%(ConstraintType, OCSN))
self.ConstraintDT.setdefault(Jnt, {})['type'] = ConstraintType
self.ConstraintDT.setdefault(Jnt, {})['ConsOBJ'] = ConstraintOBJ
mc.delete(OCSN)
Loc = mc.spaceLocator(p=(0,0,0))
mc.delete(mc.parentConstraint(Jnt, Loc))
ConstraintNode = mc.parentConstraint(Loc[0], Jnt)
self.ConstraintLocators.append(Loc[0])
self.ConstraintLocators.append(ConstraintNode[0])
示例10: setDeformerAttrConnections
def setDeformerAttrConnections(self):
'''
Set custom (non-standard) deformer attribute connections based on the stored deformer connection data.
'''
# ====================================
# - Set Custom Attribute Connections -
# ====================================
for attr in self._data['attrConnectionDict'].iterkeys():
# Define Deformer Attribute
deformerAttr = self._data['name']+'.'+attr
# Check connection destination
if not mc.objExists(deformerAttr):
print('Deformer attribute connection destination "'+deformerAttr+'" does not exist!('+self._data['name']+')')
continue
# Check connection destination settable state
if not mc.getAttr(deformerAttr,se=True):
print('Deformer attribute connection destination "'+deformerAttr+'" is not settable!('+self._data['name']+')')
continue
# Check connection source
if not mc.objExists(self._data['attrConnectionDict'][attr]):
print('Deformer attribute connection source "'+self._data['attrConnectionDict'][attr]+'" does not exist!('+self._data['name']+')')
continue
# Create Connection
mc.connectAttr(self._data['attrConnectionDict'][attr],deformerAttr,f=True)
示例11: doRenderRig
def doRenderRig(self) :
path = str(self.ui.path_lineEdit.text())
texturePath = '%s/textures' % path
renderRes = str(self.ui.renderRes_comboBox.currentText())
facialCore.path = texturePath
facialCore.res = renderRes
if mc.objExists(self.defaultHeadName) :
# rename
mc.rename(self.defaultHeadName, self.renderHeadName)
# group
group = mc.group(em = True, n = self.stillGroup)
mc.parent(self.renderHeadName, group)
# render node
ltNode = facialCore.makeRenderFacial()
# create lambert
if not mc.objExists(self.renderNode) :
vrayMtl = mc.shadingNode('VRayMtl', asShader = True, n = self.renderNode)
# connect
mc.connectAttr('%s.outColor' % ltNode, '%s.color' % vrayMtl, f = True)
# assign
mc.select(self.renderHeadName)
mc.hyperShade(assign = vrayMtl)
self.messageBox('Success', 'Set Render Node Complete')
else :
self.messageBox('Warning', '%s not Exists' % self.defaultHeadName)
示例12: bsManUpdateTargetsFromUI
def bsManUpdateTargetsFromUI():
'''
'''
# Get UI Data
blendShape = mc.textScrollList('bsMan_blendShapeTSL',q=True,si=True)
if not blendShape:
print('No blendShape node selected!')
return
base = mc.textScrollList('bsMan_baseGeomTSL',q=True,si=True)
if not base: raise Exception('No base (old) geometry specified!')
oldBase = base[0]
newBase = mc.textFieldButtonGrp('bsMan_updateTargetTFB',q=True,text=True)
targetList = mc.textScrollList('bsMan_targetsTSL',q=True,si=True)
# Checks
if not glTools.utils.blendShape.isBlendShape(blendShape[0]):
raise Exception('BlendShape "'+blendShape[0]+'" does not exist!')
if not mc.objExists(oldBase):
raise Exception('Old base geometry "'+oldBase+'" does not exist!')
if not mc.objExists(newBase):
raise Exception('New base geometry "'+newBase+'" does not exist!')
if not targetList: raise Exception('Empty target list!')
# Get Target Geometry
targetGeoList = []
for target in targetList:
targetGeo = glTools.utils.blendShape.getTargetGeo(blendShape[0],target,baseGeo=oldBase)
if not targetGeo:
print('No target geometry found for target name"'+target+'"! Skipping')
continue
targetGeoList.append(targetGeo)
# Update Targets
glTools.tools.blendShape.updateTargets(oldBase,newBase,targetGeoList)
示例13: connectToTargetFromUI
def connectToTargetFromUI():
'''
'''
# Get UI Data
blendShape = mc.textScrollList('bsMan_blendShapeTSL',q=True,si=True)
if not blendShape:
print('No blendShape node selected!')
return
base = mc.textScrollList('bsMan_baseGeomTSL',q=True,si=True)
if not base: base = ['']
target = mc.textScrollList('bsMan_targetsTSL',q=True,si=True)
if not target:
print('No blendShape target selected!')
return
targetGeo = mc.textFieldButtonGrp('bsMan_connectTargetTFB',q=True,text=True)
targetWt = mc.floatSliderGrp('bsMan_connectTargetFSG',q=True,v=True)
# Checks
if not glTools.utils.blendShape.isBlendShape(blendShape[0]):
raise Exception('BlendShape "'+blendShape[0]+'" does not exist!')
if base[0] and not mc.objExists(base[0]):
raise Exception('Base geometry "'+base[0]+'" does not exist!')
if not mc.objExists(targetGeo):
raise Exception('Target geometry "'+targetGeo+'" does not exist!')
# Add BlendShape Target Inbetween
glTools.utils.blendShape.connectToTarget( blendShape=blendShape[0],
targetGeo=targetGeo,
targetName=targetName[0],
baseGeo=base[0],
weight=1.0 )
# Reload
reloadUI()
示例14: addTargetFromUI
def addTargetFromUI():
'''
'''
# Get UI Data
blendShape = mc.textScrollList('bsMan_blendShapeTSL',q=True,si=True)
if not blendShape:
print('No blendShape node selected!')
return
base = mc.textScrollList('bsMan_baseGeomTSL',q=True,si=True)
if not base: base = ['']
targetGeo = mc.textFieldButtonGrp('bsMan_addTargetGeoTFB',q=True,text=True)
targetName = mc.textFieldGrp('bsMan_addTargetNameTFG',q=True,text=True)
# Checks
if not glTools.utils.blendShape.isBlendShape(blendShape[0]):
raise Exception('BlendShape "'+blendShape[0]+'" does not exist!')
if base[0] and not mc.objExists(base[0]):
raise Exception('Base geometry "'+base[0]+'" does not exist!')
if not mc.objExists(targetGeo):
raise Exception('Target geometry "'+targetGeo+'" does not exist!')
# Add BlendShape Target
glTools.utils.blendShape.addTarget( blendShape=blendShape[0],
target=targetGeo,
base=base[0],
targetIndex=-1,
targetAlias=targetName,
targetWeight=0.0,
topologyCheck=False )
# Reload
reloadUI()
示例15: addOverrideTarget
def addOverrideTarget(geo, targetGeo, targetWeight=0):
"""
Add override blendShape target to the specified geometry.
@param geo: The geometry to add an override blendShape target to.
@type geo: str
@param targetGeo: The override target geometry to add to the blendShape deformer.
@type targetGeo: str
@param targetWeight: The override target blend weight to apply.
@type targetWeight: float
"""
# Checks
if not cmds.objExists(geo):
raise Exception('Base geometry "' + geo + '" does not exist!!')
if not cmds.objExists(targetGeo):
raise Exception('Target geometry "' + targetGeo + '" does not exist!!')
# Get Override BlendShape
blendShape = geo.split(":")[-1] + "_override_blendShape"
if not cmds.objExists(blendShape):
blendShape = geo + "_override_blendShape"
if not cmds.objExists(blendShape):
raise Exception('Override blendShape "' + blendShape + '" does not exist!!')
# Add Target
targetAttr = glTools.utils.blendShape.addTarget(
blendShape=blendShape, target=targetGeo, base=geo, targetWeight=targetWeight, topologyCheck=False
)
# Return Result
return targetAttr