本文整理汇总了Python中maya.cmds.getAttr函数的典型用法代码示例。如果您正苦于以下问题:Python getAttr函数的具体用法?Python getAttr怎么用?Python getAttr使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了getAttr函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: setRotate_keepJointOrient
def setRotate_keepJointOrient( mtx, jnt ):
jntP = cmds.listRelatives( jnt, p=1 )[0]
joValue = cmds.getAttr( jnt+'.jo' )[0]
joMEuler = om.MEulerRotation( math.radians( joValue[0] ), math.radians( joValue[1] ), math.radians( joValue[2] ) )
joTransform = mpx.MPxTransformationMatrix( om.MMatrix() )
joTransform.rotateBy( joMEuler )
jo_im = joTransform.asMatrixInverse()
jntP_wim_list = cmds.getAttr( jntP+'.wim' )
jntP_wim = om.MMatrix()
om.MScriptUtil.createMatrixFromList( jntP_wim_list, jntP_wim )
cuMtx = mtx*jntP_wim*jo_im
transform = mpx.MPxTransformationMatrix( cuMtx )
rot = transform.eulerRotation().asVector()
degrees = [math.degrees( rot.x ), math.degrees( rot.y ), math.degrees( rot.z )]
for i in range( len( degrees ) ):
if degrees[i] > 180:
degrees[i] = degrees[i]-360
elif degrees[i] < -180:
degrees[i] = degrees[i]+360
cmds.setAttr( jnt+'.r', *degrees )
示例2: reset
def reset(self, ctrl, key=0, keyPreviousFrame=0):
"""
Reset spaces constraint offsets for the specified control
@param ctrl: Control whose spaces target offset values will be rest
@type ctrl: str
@param key: Set keyframe after reset
@type key: bool
@param keyPreviousFrame: Set keyframe before reset. Only relevant when "key" is also True.
@type keyPreviousFrame: bool
"""
# Get spaces info
spacesNode = self.getSpacesNode(ctrl)
spacesNodeConstraint = self.getSpacesConstraint(ctrl)
# Check spaces attribute
if not cmds.objExists(spacesNode + '.spaces'):
raise UserInputError('Object ' + spacesNode + 'does not contain a ".spaces" attribute!')
targetIndex = cmds.getAttr(spacesNode + '.spaces')
target = self.targetList(ctrl)[targetIndex]
# Key previous frame
if keyPreviousFrame: self.key(ctrl, [], cmds.currentTime(q=True) - 1, )
# Reset Offset Values
translateOffset = cmds.getAttr(spacesNode + '.defaultOffset[' + str(targetIndex) + '].dot')[0]
rotateOffset = cmds.getAttr(spacesNode + '.defaultOffset[' + str(targetIndex) + '].dor')[0]
cmds.setAttr(spacesNode + '.tot', translateOffset[0], translateOffset[1], translateOffset[2])
cmds.setAttr(spacesNode + '.tor', rotateOffset[0], rotateOffset[1], rotateOffset[2])
# Key current frame
if key: self.key(ctrl)
示例3: removeFloatVariable
def removeFloatVariable(self, nodeAttr, varslayout, index):
# Remove variable
children = cmds.columnLayout(varslayout, query=1, childArray=1)
if len(children) <= index:
return
baseNameAttr = nodeAttr
baseValueAttr = nodeAttr.replace("fparam_name", "fparam_value");
for i in xrange(index+1, len(children)):
rembtn, namefld, _, valfld = cmds.formLayout(children[i], query=1, childArray=1)
indexStr = "[%d]" % (i - 1)
nextIndexStr = "[%d]" % i
nameAttr = baseNameAttr + indexStr
valueAttr = baseValueAttr + indexStr
cmds.setAttr(nameAttr, cmds.getAttr(baseNameAttr + nextIndexStr), type="string")
cmds.setAttr(valueAttr, cmds.getAttr(baseValueAttr + nextIndexStr));
self.setupVariableNameCallback(nameAttr, namefld)
self.setupFloatVariableValueCallback(valueAttr, valfld)
cmds.button(rembtn, edit=1, command=lambda *args: self.removeFloatVariable(nodeAttr, varslayout, i-1))
cmds.deleteUI(children[index])
cmds.removeMultiInstance("%s[%d]" % (baseNameAttr, len(children)-1), b=True)
cmds.removeMultiInstance("%s[%d]" % (baseValueAttr, len(children)-1), b=True)
示例4: maya_move
def maya_move(angular_velocity, time_step):
objects = cmds.ls(sl=True)
if objects == []:
print('* Please select at least an object.')
return
trajectory = cmds.ls('trajectory')
for i, o in enumerate(objects):
x = cmds.getAttr(o + '.translateX')
y = cmds.getAttr(o + '.translateY')
z = cmds.getAttr(o + '.translateZ')
loc = [x, y, z]
state = make_state(loc)
state = simulate_circle(state, angular_velocity, time_step)
old_loc = loc
loc = get_location(state)
cmds.select(o)
cmds.move(loc[0], loc[1], loc[2])
# draw trajectory for the first object
if i == 0:
if trajectory == []:
cv = cmds.curve(point=[old_loc, loc], degree=1)
cmds.rename(cv, 'trajectory')
else:
cmds.curve('trajectory', point=[loc], degree=1, append=True)
# keep all objects selected
cmds.select(objects)
示例5: apply
def apply( self, mapping, **kwargs ):
'''
construct a mel string to pass to eval - so it can be contained in a single undo...
'''
cmdQueue = api.CmdQueue()
#gather options...
additive = kwargs.get( self.kOPT_ADDITIVE,
self.kOPT_DEFAULTS[ self.kOPT_ADDITIVE ] )
for clipObj, tgtObj in mapping.iteritems():
try:
attrDict = self[ clipObj ]
except KeyError: continue
for attr, value in attrDict.iteritems():
attrpath = '%s.%s' % (tgtObj, attr)
try:
if not cmd.getAttr( attrpath, settable=True ): continue
except TypeError: continue
if additive: value += cmd.getAttr( attrpath )
cmdQueue.append( 'setAttr -clamp %s %s;' % (attrpath, value) )
cmdQueue()
示例6: __init__
def __init__(self, name):
Obj.__init__(self, name)
self.resx = mc.getAttr('defaultResolution.width')
self.resy = mc.getAttr('defaultResolution.height')
self.aperture = mc.getAttr("%s.hfa" % self.name) * 25.4
self.interaxial = mc.getAttr('%s.isep' % self.name)
self.ZPS = mc.getAttr('%s.zp' % self.name)
示例7: get_num_cvs
def get_num_cvs(self, curve):
'''
Desc:
Get cvs lenght from a curve
Parameter:
curve = curve to get cvs positin list from
coords_space = the coordinat space, can be "world" (default), or "local"
Return:
list with positions
'''
# If curve is nod define or not correct release error
if curve:
# Get curve shape
curve_shape = KstMaya.get_shape_node(curve)
# Get degree
degree = cmds.getAttr(curve_shape+".degree")
# Get spans
spans = cmds.getAttr(curve_shape+".spans")
# Calulating ncvs with formula spans+degree
ncvs = spans+degree
# Return the list
return ncvs
else:
cmds.warning("Curve %s, is not defined, or is not a curve, double check!" % curve)
return None
示例8: getComponent
def getComponent(textureNode, component='color'):
if not 'dead_space' in cmds.getAttr(textureNode+'.fileTextureName'):
cmds.warning('Cannot create component beacause this is not a DS texture.')
if not component in ('color', 'normal', 'specular'):
cmds.warning("Please put one of the following component: 'color', 'normal', 'specular'")
texturePath = cmds.getAttr(textureNode+'.fileTextureName')
textureComponent = os.path.dirname(texturePath).split('/')[-1]
if textureComponent == component:
cmds.warning('You are trying to get the same component as the texture selected.')
componentPath = os.path.dirname(texturePath).replace(textureComponent, component)
if os.path.exists(componentPath):
originalComp = COMPS[textureComponent]
replaceComp = COMPS[component]
else:
cmds.warning('Cannot find component path.')
componentTexturePath = componentPath+'/'+os.path.basename(texturePath).replace(originalComp, replaceComp)
if os.path.isfile(componentTexturePath):
return componentTexturePath
else:
#cmds.warning('Cannot find component texture file.')
return None
示例9: returnClosestUV
def returnClosestUV (targetObject,surface):
"""
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
DESCRIPTION:
Pass target object and surface into it and return the closest UV coordinates
ARGUMENTS:
targetObject(string)
surface(string)
RETURNS:
UV(string)
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
"""
""" pass target object and surface into it and return the closest UV coordinates"""
UVs = []
""" make the node """
tmpNode = mc.createNode ('closestPointOnSurface')
""" to account for target objects in heirarchies """
tmpObj = rigging.locMeObjectStandAlone(targetObject)
mc.connectAttr ((tmpObj+'.translate'),(tmpNode+'.inPosition'))
mc.connectAttr ((surface+'.worldSpace'),(tmpNode+'.inputSurface'))
UVs.append (mc.getAttr (tmpNode+'.u'))
UVs.append (mc.getAttr (tmpNode+'.v'))
mc.delete (tmpNode)
mc.delete (tmpObj)
return UVs
示例10: grow
def grow(self):
scaleX = cmds.getAttr("%s.scaleX"%self.sphere)
scaleZ = cmds.getAttr("%s.scaleZ"%self.sphere)
newScaleX = scaleX * 1.5
newScaleZ = scaleZ * 1.5
cmds.setAttr("%s.scaleX"%self.sphere, newScaleX)
cmds.setAttr("%s.scaleZ"%self.sphere, newScaleZ)
示例11: CentreUVs
def CentreUVs():
objSel = cmds.ls(sl=True)
try:
for item, x in enumerate(objSel):
cmds.select('%s.map[*]' %objSel[item])
mm.eval("PolySelectConvert 4;")
mm.eval('TranslateToolWithSnapMarkingMenu')
objPiv = cmds.getAttr('%s.uvPivot' %objSel[0])
mm.eval('MarkingMenuPopDown')
objCenterU = 0.5 - objPiv[0][0]
objCenterV = 0.5 - objPiv[0][1]
cmds.polyEditUV(u=objCenterU, v=objCenterV, r=1)
cmds.select(objSel)
except ValueError:
objQuery = cmds.listRelatives(objSel[0], ap=True)
cmds.select('%s.map[*]' %objQuery[0])
mm.eval("PolySelectConvert 4;")
mm.eval('TranslateToolWithSnapMarkingMenu')
objPiv = cmds.getAttr('%s.uvPivot' %objQuery[0])
mm.eval('MarkingMenuPopDown')
objCenterU = 0.5 - objPiv[0][0]
objCenterV = 0.5 - objPiv[0][1]
cmds.polyEditUV(u=objCenterU, v=objCenterV, r=1)
cmds.select(objQuery)
示例12: check_transforms
def check_transforms(objects):
'''
Check joints to insure they have no rotation values.
'''
invalid = []
cmds.select(objects)
new_objects = cmds.pickWalk(d='up')
t_r_xform = ['t', 'r']
scale_xform = 's'
axis = ['x', 'y', 'z']
for obj in new_objects:
#check translates rotates and scales
for trans in t_r_xform:
#check each axis
for ax in axis:
trans_rot = cmds.getAttr('%s.%s%s' % (obj, trans, ax))
if trans_rot != 0:
invalid.append(obj)
break
for ax in axis:
scale = cmds.getAttr('%s.%s%s' % (obj, scale_xform, ax))
if scale != 1:
invalid.append(obj)
break
return invalid
示例13: deformCharacterShapeSel
def deformCharacterShapeSel(self, value):
RN = mc.referenceQuery(self.core.skCharacter[int(value)-1], referenceNode=1)
Nodes = mc.referenceQuery(RN, nodes=1)
self.characterdeformShape = []
self.allCharacterRightdeformShape = []
for item in Nodes:
if self.nodeTypeSelf(item) in self.shapeType:
self.characterdeformShape.append(item)
for each in self.characterdeformShape:
itemP = mc.listRelatives(each, p=1)[0]
itemPP = mc.listRelatives(itemP, p=1)
if itemPP != None and mc.getAttr('%s.v'%itemP) != 0 and mc.getAttr('%s.v'%itemPP[0]) != 0:
self.allCharacterRightdeformShape.append(each)
self.allCharacterRightdeformShape.reverse()
for item in self.allCharacterRightdeformShape:
if mc.filterExpand( item, sm=(10,12)) == None:
self.allCharacterRightdeformShape.remove(item)
for item in self.allCharacterRightdeformShape:
if item.endswith('Orig') == True:
self.allCharacterRightdeformShape.remove(item)
for item in self.allCharacterRightdeformShape:
if item.endswith('Orig') == True:
self.allCharacterRightdeformShape.remove(item)
for item in self.allCharacterRightdeformShape:
if item.endswith('Orig') == True:
self.allCharacterRightdeformShape.remove(item)
for item in self.allCharacterRightdeformShape:
if item.endswith('Orig') == True:
self.allCharacterRightdeformShape.remove(item)
for item in self.allCharacterRightdeformShape:
if item.endswith('Orig') == True:
self.allCharacterRightdeformShape.remove(item)
return self.allCharacterRightdeformShape
示例14: writeSetAttrCmd
def writeSetAttrCmd( trigger, connectIdxs=None ):
cmdToks = []
assert isinstance( trigger, Trigger )
if connectIdxs is None:
connectIdxs = [ idx for _,idx in trigger.connects() ]
#make sure the zeroth connect isn't in the list and remove duplicates
connectIdxs = removeDupes( connectIdxs )
if 0 in connectIdxs:
connectIdxs.remove( 0 )
for connectIdx in connectIdxs:
obj = trigger[connectIdx]
attrs = cmd.listAttr( obj, k=True, s=True, v=True, m=True ) or []
objTrigger = Trigger( obj )
for a in attrs:
attrPath = '%s.%s' % (obj, a)
attrType = cmd.getAttr( attrPath, type=True )
attrValue = cmd.getAttr( attrPath )
if attrType.startswith( 'double' ):
cmdToks.append( "setAttr %%%d.%s %0.5f;" % (connectIdx, a, attrValue) )
else:
cmdToks.append( "setAttr %%%d.%s %d;" % (connectIdx, a, attrValue) )
return '\n'.join( cmdToks )
示例15: goToObject
def goToObject(self, first, second, *args ):
if cmds.nodeType( first ) == 'joint':
jo = cmds.getAttr( first+'.jo' )[0]
mpxTransform = mpx.MPxTransformationMatrix()
rotVector = om.MVector( math.radians( jo[0] ), math.radians( jo[1] ), math.radians( jo[2] ) )
mpxTransform.rotateTo( om.MEulerRotation( rotVector ) )
joMtx = mpxTransform.asMatrix()
fMtx = om.MMatrix()
fPMtx = om.MMatrix()
fMtxList = cmds.getAttr( first+'.wm' )
fPMtxList = cmds.getAttr( first+'.pm' )
sMtx = om.MMatrix()
sMtxList = cmds.getAttr( second+'.wm' )
om.MScriptUtil.createMatrixFromList( fMtxList, fMtx )
om.MScriptUtil.createMatrixFromList( fPMtxList, fPMtx )
om.MScriptUtil.createMatrixFromList( sMtxList, sMtx )
sMtxPose = [ sMtx(3,0), sMtx(3,1), sMtx(3,2) ]
rMtx = sMtx*(joMtx*fPMtx).inverse()
rTransform = mpx.MPxTransformationMatrix( rMtx )
rVector = rTransform.eulerRotation().asVector()
rot = [ math.degrees( rVector.x ), math.degrees( rVector.y ), math.degrees( rVector.z ) ]
cmds.setAttr( first+'.r', *rot )
cmds.move( sMtxPose[0], sMtxPose[1], sMtxPose[2], first, ws=1 )
else:
rigbase.goToSamePosition( first, second )