本文整理汇总了Python中maya.cmds.objectType函数的典型用法代码示例。如果您正苦于以下问题:Python objectType函数的具体用法?Python objectType怎么用?Python objectType使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了objectType函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: doIt
def doIt(self, argList):
# get objects from argument list (size >= 2)
try:
obj = misc.getArgObj(self.syntax(), argList)
if (len(obj) < 2):
cmds.error("Select at least 2 objects!")
return
if (cmds.objectType(obj[0]) != 'transform' or cmds.objectType(obj[1]) != 'transform'):
cmds.error("Object is not of type transform!")
return
except:
cmds.warning("No objects selected or only one object given!")
return
argData = om.MArgParser(self.syntax(), argList)
# read all arguments and set default values
keepCD = argData.flagArgumentBool('keepConvexDecomposition', 0) if (argData.isFlagSet('keepConvexDecomposition')) else True
nvol = argData.flagArgumentDouble('normVolume', 0) if (
argData.isFlagSet('normVolume')) else 100.0
norm = argData.flagArgumentBool('norm', 0) if (
argData.isFlagSet('norm')) else True
s_file = os.path.abspath(argData.flagArgumentString('saveFile', 0)) if (argData.isFlagSet('saveFile')) else ""
save = False
if s_file != "":
o_file = open(s_file, 'w')
o_file.write("i0, i1, name0, name1, its_volume, dice\n")
save = True
# get all flags for vhacd over static parsing method
vhacd_par = vhacd.vhacd.readArgs(argData)
if (vhacd_par is None):
cmds.error("V-HACD: one or more arguments are invalid!")
return
#norm the volume
if norm:
for o in obj:
v = cmds.getVolume(o)
scale_factor = (nvol/ v) ** (1./3)
# cmds.xform(o, scale=[scale_factor, scale_factor, scale_factor])
cmds.scale(scale_factor, scale_factor, scale_factor, o, relative=True)
cmds.makeIdentity(o, apply=True)
intersection_matrix = np.matrix(str(cmds.intersection(obj, kcd=keepCD, matlabOutput=True, **vhacd_par)))
dice_matrix = np.matrix(intersection_matrix)
for i in range(0, intersection_matrix.shape[0]):
for j in range(i, intersection_matrix.shape[1]):
its_volume = intersection_matrix[i, j]
dice_matrix[i, j] = (its_volume*2)/(intersection_matrix[i, i]+intersection_matrix[j, j])
if save:
o_file.write(",".join((str(i), str(j), obj[i], obj[j], str(its_volume), str(dice_matrix[i, j]))))
o_file.write("\n")
o_file.flush()
if save:
o_file.close()
self.setResult(str(dice_matrix))
示例2: setDrawOverrideColor
def setDrawOverrideColor( obj, color=17 ):
"""
edit the given object's shape node override color
"""
shapes = []
if not cmd.objectType( obj, i='nurbsCurve' ) or not cmd.objectType( obj, i='nurbsSurface' ) or not cmd.objectType( obj, i='mesh' ):
shapes.append( obj )
for s in listRelatives( obj, s=True, pa=True ) or []:
shapes.append( s )
if shapes:
for s in shapes:
conns = cmd.listConnections( '%s.drawOverride' % s, s=True )
if not conns:
if not color == 0:
cmd.setAttr ('%s.overrideEnabled' % s, e=True, l=False )
cmd.setAttr ('%s.overrideEnabled' % s, 1 )
cmd.setAttr ('%s.overrideColor' % s, e=True, l=False )
cmd.setAttr ('%s.overrideColor' % s, color )
else:
cmd.color( s )
cmd.setAttr ('%s.overrideColor' % s, e=True, l=False )
cmd.setAttr ('%s.overrideColor' % s, color )
cmd.setAttr ('%s.overrideEnabled' % s, e=True, l=False )
cmd.setAttr ('%s.overrideEnabled' % s, 0 )
#end
示例3: addScalePP
def addScalePP(particle):
"""
Add a per particle vector(Array) attribute named "scalePP", to the specified particle object.
An initial state attribute "scalePP0" will also be created.
@param particle: The particle or nParticle object to add the attribute to
@type particle: str
"""
# Check Particle
if not cmds.objExists(particle):
raise Exception('Particle "' + particle + '" does not exist!')
if cmds.objectType(particle) == 'transform':
particleShape = cmds.listRelatives(particle, s=True)
if not particleShape:
raise Exception('Unable to determine particle shape from transform "' + particle + '"!')
else:
particle = particleShape[0]
if (cmds.objectType(particle) != 'particle') and (cmds.objectType(particle) != 'nParticle'):
raise Exception('Object "' + particle + '" is not a valid particle or nParticle object!')
# Add rotatePP attribute
if not cmds.objExists(particle + '.scalePP0'):
cmds.addAttr(particle, ln='scalePP0', dt='vectorArray')
if not cmds.objExists(particle + '.scalePP'):
cmds.addAttr(particle, ln='scalePP', dt='vectorArray')
# Return Result
return particle + '.scalePP'
示例4: getParentConstraintDic
def getParentConstraintDic (self, parentConstraint) :
returnedDic = {'alias':{}, "object":None }
aliasDic={}
if cmds.objectType(parentConstraint)=="parentConstraint":
WA = cmds.parentConstraint (parentConstraint, q = True, weightAliasList = True)
TL = cmds.parentConstraint (parentConstraint, q = True, targetList = True)
elif cmds.objectType(parentConstraint)=="orientConstraint":
WA = cmds.orientConstraint (parentConstraint, q = True, weightAliasList = True)
TL = cmds.orientConstraint (parentConstraint, q = True, targetList = True)
elif cmds.objectType(parentConstraint)=="pointConstraint":
WA = cmds.pointConstraint (parentConstraint, q = True, weightAliasList = True)
TL = cmds.pointConstraint (parentConstraint, q = True, targetList = True)
else:
"error No constraint Type identified"
if len(WA) == len(TL):
for eachWAIndex in range(0,len(WA)):
aliasDic[WA[eachWAIndex]] = TL[eachWAIndex]
returnedDic["object"] = cmds.listConnections(parentConstraint + ".constraintRotateX")[0]
returnedDic["alias"] = aliasDic
return returnedDic
示例5: attachCurves
def attachCurves(name, identifier, jobInfo, isConstant=False):
cmds.ExocortexAlembic_profileBegin(f="Python.ExocortexAlembic._attach.attachCurves")
if cmds.objExists( name ):
curObj = cmds.connectionInfo(name+".visibility", sfd=True)
if curObj and cmds.objectType(curObj) == "ExocortexAlembicCurvesDeform":
attachTimeAndFile(curObj, jobInfo, isConstant)
return
# create deformer, and attach time and file
newDform = cmds.deformer(name, type="ExocortexAlembicCurvesDeform")[0]
cmds.setAttr(newDform+".identifier", identifier, type="string")
attachTimeAndFile(newDform, jobInfo, isConstant)
# get curObj new "output" attribute connection
if cmds.objExists( curObj ):
if curObj != None and cmds.objectType(curObj) != "ExocortexAlembicCurves":
originalCur = cmds.connectionInfo(curObj+".output", sfd=True).split('.')[0]
cmds.delete(curObj)
curObj = cmds.createNode("ExocortexAlembicCurves")
attachTimeAndFile(curObj, jobInfo, isConstant)
cmds.connectAttr(curObj+".outCurve", originalCur+".create")
cmds.connectAttr(jobInfo.filenode+".outFileName", curObj+".fileName")
cmds.setAttr(curObj+".identifier", identifier, type="string")
cmds.ExocortexAlembic_profileEnd(f="Python.ExocortexAlembic._attach.attachCurves")
pass
示例6: altFrame
def altFrame(*args):
# cmds.nodeType(sel), object type
# optimize, real slow
pnl = cmds.getPanel(withFocus=True)
typ = cmds.getPanel(typeOf=pnl)
if typ == 'modelPanel':
sel = cmds.ls(sl=True, fl=True)
gs = ac.GraphSelection()
locs = []
if sel:
for item in sel:
if cmds.objectType(item, i='transform') or cmds.objectType(item, i='joint'):
loc = cn.locator(obj=item, ro='zxy', X=0.35, constrain=False, shape=False)[0]
locs.append(loc)
else:
try:
print cmds.listRelatives(item, parent=True)[0], '_______________'
loc = cn.locator(obj=cmds.listRelatives(item, parent=True)[0], ro='zxy', X=0.35, constrain=False, shape=False)
print loc, '_____________________'
loc = loc[0]
locs.append(loc)
except:
message('didnt frame object: ' + item)
cmds.select(locs)
mel.eval("fitPanel -selected;")
cmds.delete(locs)
gs.reselect()
else:
message('select an object')
else:
mel.eval("fitPanel -selected;")
示例7: __add_atributes_to_yeti_nodes
def __add_atributes_to_yeti_nodes(self):
#get all the transform of the yeti nodes
objs = cmds.ls(type='pgYetiMaya', transforms=True)
objs = objs + cmds.ls(type='pgYetiGroom', transforms=True)
yetinodes = []
for i in objs:
if cmds.objectType(i, isType='pgYetiMaya') or cmds.objectType(i, isType='pgYetiGroom'):
yetinodes.append(i)
cmds.select(cl=True)
long_name = "connectedMeshName"
nice_name = "Connected Mesh Name"
long_name_u = "connectedMeshUUID"
nice_name_u = "Connected Mesh UUID"
# add the name and uuid of the connected mesh to the yeti node
for i in yetinodes:
inputGeometryList = cmds.listConnections(i + ".inputGeometry", s=True, sh=True)
count = 0
for geo in inputGeometryList:
object_uuid = cmds.ls(geo, uuid=True)[0]
object_name = geo
transform = cmds.listRelatives(i, parent=True)[0]
cmds.addAttr(transform, ln=long_name + '' + str(count), nn=nice_name, dt="string")
cmds.setAttr(transform + '.' + long_name + '' + str(count), object_name, type="string")
cmds.setAttr(transform + '.' + long_name + '' + str(count), lock=True, type="string")
cmds.addAttr(transform, ln=long_name_u + '' + str(count), nn=nice_name_u, dt="string")
cmds.setAttr(transform + '.' + long_name_u + '' + str(count), object_uuid, type="string")
cmds.setAttr(transform + '.' + long_name_u + '' + str(count), lock=True, type="string")
count += 1
示例8: transferUvHierarchy
def transferUvHierarchy( fromTopGroup, toTopGroup):
fromChildren = cmds.listRelatives( fromTopGroup, ad=True, type='mesh', fullPath=True)[1:]
toChildren = cmds.listRelatives( toTopGroup, ad=True, type='mesh', fullPath=True)[1:]
print fromChildren
tmp = copy.copy(fromChildren)
for fChild in tmp:
split = fChild.split("|")[1:]
#print split
split[0] = toTopGroup
tChild = "|" + "|".join( split)
print fChild, tChild
if tChild in toChildren:
fromChildren.remove( fChild)
toChildren.remove( tChild)
cmds.select( fChild, r=True)
tShapes = getShapes(tChild)
print 'transfered \n%s \n | \n%s' % (fChild, tChild)
tChildShapeOrig = tShapes[0]+'Orig'
if (cmds.objectType(fChild) == 'transform' and cmds.objectType(tChild) == 'transform' and cmds.objectType(tChildShapeOrig) == 'mesh'):
cmds.select( tChildShapeOrig, add=True)
cmds.transferAttributes( transferPositions=0, transferNormals=0, transferUVs=2, transferColors=0, sampleSpace=4, sourceUvSpace="map1", targetUvSpace="map1", searchMethod=3, flipUVs=0, colorBorders=1)
print toChildren
print fromChildren
示例9: __init__
def __init__(self,deformer=''):
'''
DeformerData class initializer.
@param deformer: Deformer to initialize data for
@type deformer: str
'''
# Check deformer
if not deformer: return
# Initialize class data members
self.deformerName = ''
self.deformerType = ''
self.deformerData = {}
# Check deformer
if not glTools.utils.deformer.isDeformer(deformer):
raise Exception('Object '+deformer+' is not a valid deformer! Unable to instantiate DeformerData() class!!')
# Get basic deformer info
self.deformerName = deformer
self.deformerType = mc.objectType(deformer)
self.envelope = mc.getAttr(deformer+'.envelope')
# Get geometry affected by deformer
affectedGeo = glTools.utils.deformer.getAffectedGeometry(deformer,returnShapes=1)
# Build data lists for each affected geometry
for geo in affectedGeo.iterkeys():
geo = str(geo)
self.deformerData[geo] = {}
self.deformerData[geo]['index'] = affectedGeo[geo]
self.deformerData[geo]['geometryType'] = str(mc.objectType(geo))
self.deformerData[geo]['membership'] = glTools.utils.deformer.getDeformerSetMemberIndices(deformer,geo)
self.deformerData[geo]['weights'] = glTools.utils.deformer.getWeights(deformer,geo)
示例10: lights_in_scene
def lights_in_scene(self):
"""List Lights in scene """
cmds.select(clear=True)
self.lights = cmds.ls(type="light")
if self.lights is False:
cmds.error("No light in scene")
cmds.select(self.lights, add=True)
self.all_lights = cmds.ls(sl=True)
self.list_spot = []
self.list_vray = []
self.list_standard = []
for s in self.all_lights:
if cmds.objectType(s, isType='spotLight'):
self.list_spot.append(s)
elif cmds.objectType(s, isType='VrayLight'):
self.list_vray.append(s)
else:
self.list_standard.append(s)
cmds.select(clear=True)
self.sp_len = len(self.list_spot)
self.vr_len = len(self.list_vray)
self.sd_len = len(self.list_standard)
cmds.select(self.all_lights[-1])
示例11: blendShapeWeightCopy
def blendShapeWeightCopy(self):
sels = cmds.ls(sl = True)
if len(sels) >= 2:
sourceObj = sels[0]
sourceShape = cmds.listRelatives(sourceObj,s = True)[0]
sourceBlendShape = cmds.listConnections(sourceShape + '.inMesh',scn = True,destination = False)
destinationObjs = sels[1:]
for destinationObj in destinationObjs:
destinationShape = cmds.listRelatives(destinationObj,s = True)[0]
destinationBlendShape = cmds.listConnections(destinationShape + '.inMesh',scn = True,destination = False)
print sourceBlendShape,destinationBlendShape
if sourceBlendShape != None:
if cmds.objectType(sourceBlendShape[0])== 'blendShape':
if destinationBlendShape != None:
if cmds.objectType(destinationBlendShape[0])== 'blendShape':
vtxs = cmds.ls(sourceShape + '.vtx[0:]',fl = True)
vtxNum = len(vtxs)
for x in range(vtxNum):
weight = cmds.getAttr('%s.it[0].bw[%d]'%( sourceBlendShape[0] , int(x)))
cmds.setAttr('%s.it[0].bw[%d]'%( destinationBlendShape[0] , int(x)),weight)
else:
cmds.warning(destinationBlendShape + ' There is no blendShape')
else:
cmds.warning(destinationBlendShape + ' There is no blendShape')
else:
cmds.warning(sourceObj + ' There is no blendShape')
else:
cmds.warning(sourceObj + ' There is no blendShape')
else:
cmds.warning('plase select at least two model')
示例12: getShapes
def getShapes(self,transform,getIntermediate=0):
'''
Return a list of shapes under a specified transform
@param transform: Transform to query
@type transform: str
@param getIntermediate: Return intermediate shapes.
@type getIntermediate: bool
'''
# Initialize arrays
returnShapes = []
# Check for shape input
if (mc.objectType(transform) == 'mesh') or (mc.objectType(transform) == 'nurbsCurve') or (mc.objectType(transform) == 'nurbsSurface'):
# Get transform parent
transform = mc.listRelatives(transform,p=1)[0] # Get element[0] from parent list
# Get shape lists
if mc.objectType(transform) == 'transform':
allShapes = mc.listRelatives(transform,s=1)
for shape in allShapes:
if mc.getAttr(shape+'.intermediateObject') == getIntermediate:
returnShapes.append(shape)
else:
raise UserInputError('Unable to find shape node for '+transform+'!')
# Return result
return returnShapes
示例13: getShape
def getShape(crv):
"""If crv is a shape node, return it. If it is
a transform with a single shape parent, return the shape.
@param crv: the shape or transform node
@raise RuntimeError: if node is not a shape and has multiple
or no shape children
"""
if MC.objectType(crv, isAType='geometryShape'):
return crv
result = None
shapes = MC.listRelatives(crv) or []
for shape in shapes:
#ni flag broken?
if MC.getAttr('%s.intermediateObject' % shape):
continue
if MC.objectType(shape, isAType='geometryShape'):
if result is not None:
raise RuntimeError("Multiple shapes under '%s'" % crv)
result = shape
if result is None:
raise RuntimeError("No shapes under '%s'" % crv)
return result
示例14: surfaceArea
def surfaceArea(surface,worldSpace=True):
'''
Calculates the surface area of a specified nurbs surface.
@param surface: Nurbs surface to calculate the surface area for
@type surface: str
@param worldSpace: Calculate the surface area in world or local space units
@type worldSpace: bool
'''
# Check Surface
if not mc.objExists(surface): raise UserInputError('Object '+surface+' does not exist!')
if mc.objectType(surface) == 'transform':
surfaceShape = mc.listRelatives(surface,s=True,ni=True)[0]
if mc.objectType(surfaceShape) != 'nurbsSurface':
raise UserInputError('Object '+surface+' is not a valid nurbs surface!')
surface = surfaceShape
# Get MFnNurbsSurface
surfaceFn = getSurfaceFn(surface)
# Get surface area
area = 0.0
if worldSpace: area = surfaceFn.area(OpenMaya.MSpace.kWorld)
else: area = surfaceFn.area(OpenMaya.MSpace.kObject)
# Return result
return area
示例15: getSingleIndexComponentList
def getSingleIndexComponentList(self,componentList=[]):
'''
Convert a 2 or 3 value index to a single value index.
getSingleIndexComponentList(componentList=[]): Returns a flat list of integer component index values.
@param componentList: A list of component names. if empty will default to selection.
@type componentList: list
'''
# Clear flattenedIndexList
singleIndexList = {}
# Get selection if componentList is empty
if not componentList: componentList = mc.ls(sl=True,fl=True)
# Set active selection
#if componentList: mc.select(componentList)
#else: return {}
if not componentList: return singleIndexList
# Get component selection
componentSel = self.getComponentIndexList(componentList)
# Iterate through shape keys
shapes = componentSel.keys()
for shape in shapes:
indexList = componentSel[shape]
if mc.objectType(shape) == 'transform':
shape = self.selectionUtils.getShapes(shape)[0]
if (mc.objectType(shape) == 'mesh') or (mc.objectType(shape) == 'nurbsCurve'):
singleIndexList[shape] = indexList
elif mc.objectType(shape) == 'nurbsSurface':
# Get nurbsSurface function set
surfList = OpenMaya.MSelectionList()
surfObj = OpenMaya.MObject()
OpenMaya.MGlobal.getSelectionListByName(shape,surfList)
surfList.getDependNode(0,surfObj)
surfFn = OpenMaya.MFnNurbsSurface(surfObj)
# CV count in V direction
numV = surfFn.numCVsInV()
# Check for periodic surface
if surfFn.formInV() == surfFn.kPeriodic:
numV -= surfFn.degreeV()
singleIndexList[shape] = []
for i in range(len(indexList)):
singleIndexList[shape].append((indexList[i][0] * numV) + indexList[i][1])
elif (mc.objectType(shape) == 'lattice'):
sDiv = mc.getAttr(shape+'.sDivisions')
tDiv = mc.getAttr(shape+'.tDivisions')
singleIndexList[shape] = []
for i in range(len(indexList)):
singleIndexList[shape].append(indexList[i][0] + (indexList[i][1] * sDiv) + (indexList[i][2] * sdiv * tDiv) )
# Return result
return singleIndexList