Sets the value of a dependency node attribute. No value for the the attribute is needed when the -l/-k/-s flags are used. The -type flag is only required when setting a non-numeric attribute. The following chart outlines the syntax of setAttr for non-numeric data types: TYPEbelow means any number of values of type TYPE, separated by a space[TYPE]means that the value of type TYPEis optionalA|Bmeans that either of Aor Bmay appearIn order to run its examples, first execute these commands to create the sample attribute types:sphere -n node; addAttr -ln short2Attr -at short2; addAttr -ln short2a -p short2Attr -at short; addAttr -ln short2b -p short2Attr -at short; addAttr -ln short3Attr -at short3; addAttr -ln short3a -p short3Attr -at short; addAttr -ln short3b -p short3Attr -at short; addAttr -ln short3c -p short3Attr -at short; addAttr -ln long2Attr -at long2; addAttr -ln long2a -p long2Attr -at long; addAttr -ln long2b -p long2Attr -at long; addAttr -ln long3Attr -at long3; addAttr -ln long3a -p long3Attr -at long; addAttr -ln long3b -p long3Attr -at long; addAttr -ln long3c -p long3Attr -at long; addAttr -ln float2Attr -at float2; addAttr -ln float2a -p float2Attr -at float; addAttr -ln float2b -p float2Attr -at float; addAttr -ln float3Attr -at float3; addAttr -ln float3a -p float3Attr -at float; addAttr -ln float3b -p float3Attr -at float; addAttr -ln float3c -p float3Attr -at float; addAttr -ln double2Attr -at double2; addAttr -ln double2a -p double2Attr -at double; addAttr -ln double2b -p double2Attr -at double; addAttr -ln double3Attr -at double3; addAttr -ln double3a -p double3Attr -at double; addAttr -ln double3b -p double3Attr -at double; addAttr -ln double3c -p double3Attr -at double; addAttr -ln int32ArrayAttr -dt Int32Array; addAttr -ln doubleArrayAttr -dt doubleArray; addAttr -ln pointArrayAttr -dt pointArray; addAttr -ln vectorArrayAttr -dt vectorArray; addAttr -ln stringArrayAttr -dt stringArray; addAttr -ln stringAttr -dt string; addAttr -ln matrixAttr -dt matrix; addAttr -ln sphereAttr -dt sphere; addAttr -ln coneAttr -dt cone; addAttr -ln meshAttr -dt mesh; addAttr -ln latticeAttr -dt lattice; addAttr -ln spectrumRGBAttr -dt spectrumRGB; addAttr -ln reflectanceRGBAttr -dt reflectanceRGB; addAttr -ln componentListAttr -dt componentList; addAttr -ln attrAliasAttr -dt attributeAlias; addAttr -ln curveAttr -dt nurbsCurve; addAttr -ln surfaceAttr -dt nurbsSurface; addAttr -ln trimFaceAttr -dt nurbsTrimface; addAttr -ln polyFaceAttr -dt polyFaces; -type short2Array of two short integersValue Syntaxshort shortValue Meaningvalue1 value2ExamplesetAttr node.short2Attr -type short2 1 2;-type short3Array of three short integersValue Syntaxshort short shortValue Meaningvalue1 value2 value3ExamplesetAttr node.short3Attr -type short3 1 2 3;-type long2Array of two long integersValue Syntaxlong longValue Meaningvalue1 value2ExamplesetAttr node.long2Attr -type long2 1000000 2000000;-type long3Array of three long integersValue Syntaxlong long longValue Meaningvalue1 value2 value3ExamplesetAttr node.long3Attr -type long3 1000000 2000000 3000000;-type Int32ArrayVariable length array of long integersValue SyntaxValue MeaningExamplesetAttr node.int32ArrayAttr -type Int32Array 2 12 75;-type float2Array of two floatsValue Syntaxfloat floatValue Meaningvalue1 value2ExamplesetAttr node.float2Attr -type float2 1.1 2.2;-type float3Array of three floatsValue Syntaxfloat float floatValue Meaningvalue1 value2 value3ExamplesetAttr node.float3Attr -type float3 1.1 2.2 3.3;-type double2Array of two doublesValue Syntaxdouble doubleValue Meaningvalue1 value2ExamplesetAttr node.double2Attr -type double2 1.1 2.2;-type double3Array of three doublesValue Syntaxdouble double doubleValue Meaningvalue1 value2 value3ExamplesetAttr node.double3Attr -type double3 1.1 2.2 3.3;-type doubleArrayVariable length array of doublesValue SyntaxValue MeaningExamplesetAttr node.doubleArrayAttr -type doubleArray 2 3.14159 2.782;-type matrix4x4 matrix of doublesValue Syntaxdouble double double doubledouble double double doubledouble double double doubledouble double double doubleValue Meaningrow1col1 row1col2 row1col3 row1col4row2col1 row2col2 row2col3 row2col4row3col1 row3col2 row3col3 row3col4row4col1 row4col2 row4col3 row4col4Alternate Syntaxstring double double doubledouble double doubleintegerdouble double doubledouble double doubledouble double doubledouble double doubledouble double doubledouble double doubledouble double double doubledouble double double doubledouble double doublebooleanAlternate MeaningxformscaleX scaleY scaleZrotateX rotateY rotateZrotationOrder (0=XYZ, 1=YZX, 2=ZXY, 3=XZY, 4=YXZ, 5=ZYX)translateX translateY translateZshearXY shearXZ shearYZscalePivotX scalePivotY scalePivotZscaleTranslationX scaleTranslationY scaleTranslationZrotatePivotX rotatePivotY rotatePivotZrotateTranslationX rotateTranslationY rotateTranslationZrotateOrientW rotateOrientX rotateOrientY rotateOrientZjointOrientW jointOrientX jointOrientY jointOrientZinverseParentScaleX inverseParentScaleY inverseParentScaleZcompensateForParentScale ExamplesetAttr node.matrixAttr -type matrix1 0 0 0 0 1 0 0 0 0 1 0 2 3 4 1;setAttr node.matrixAttr -type matrixxform1 1 1 0 0 0 0 2 3 4 0 0 00 0 0 0 0 0 0 0 0 0 0 1 1 0 0 1 0 1 0 1 1 1 0 false;-type pointArrayVariable length array of pointsValue SyntaxValue MeaningExamplesetAttr node.pointArrayAttr -type pointArray 2 1 1 1 1 2 2 2 1;-type vectorArrayVariable length array of vectorsValue SyntaxValue MeaningExamplesetAttr node.vectorArrayAttr -type vectorArray 2 1 1 1 2 2 2;-type stringCharacter stringValue SyntaxstringValue MeaningcharacterStringValueExamplesetAttr node.stringAttr -type stringblarg;-type stringArrayVariable length array of stringsValue SyntaxValue MeaningExamplesetAttr node.stringArrayAttr -type stringArray 3 abc;-type sphereSphere dataValue SyntaxdoubleValue MeaningsphereRadiusExamplesetAttr node.sphereAttr -type sphere 5.0;-type coneCone dataValue Syntaxdouble doubleValue MeaningconeAngle coneCapExamplesetAttr node.coneAttr -type cone 45.0 5.0;-type reflectanceRGBReflectance dataValue Syntaxdouble double doubleValue MeaningredReflect greenReflect blueReflectExamplesetAttr node.reflectanceRGBAttr -type reflectanceRGB 0.5 0.5 0.1;-type spectrumRGBSpectrum dataValue Syntaxdouble double doubleValue MeaningredSpectrum greenSpectrum blueSpectrumExamplesetAttr node.spectrumRGBAttr -type spectrumRGB 0.5 0.5 0.1;-type componentListVariable length array of componentsValue SyntaxValue MeaningExamplesetAttr node.componentListAttr -type componentList 3 cv[1] cv[12] cv[3];-type attributeAliasString alias dataValue Syntaxstring stringValue MeaningnewAlias currentNameExamplesetAttr node.attrAliasAttr -type attributeAliasGoUp, translateY, GoLeft, translateX;-type nurbsCurveNURBS curve dataValue SyntaxValue MeaningExample// degree is the degree of the curve(range 1-7)// spans is the number of spans // form is open (0), closed (1), periodic (2)// dimension is 2 or 3, depending on the dimension of the curve// isRational is true if the curve CVs contain a rational component // knotCount is the size of the knot list// knotValue is a single entry in the knot list// cvCount is the number of CVs in the curve// xCVValue,yCVValue,[zCVValue] [wCVValue] is a single CV.// zCVValue is only present when dimension is 3.// wCVValue is only present when isRational is true.//setAttr node.curveAttr -type nurbsCurve 3 1 0 no 36 0 0 0 1 1 14 -2 3 0 -2 1 0 -2 -1 0 -2 -3 0;-type nurbsSurfaceNURBS surface dataValue Syntaxint int int int bool Value MeaninguDegree vDegree uForm vForm isRationalTRIM|NOTRIMExample// uDegree is degree of the surface in U direction (range 1-7)// vDegree is degree of the surface in V direction (range 1-7)// uForm is open (0), closed (1), periodic (2) in U direction// vForm is open (0), closed (1), periodic (2) in V direction// isRational is true if the surface CVs contain a rational component// uKnotCount is the size of the U knot list// uKnotValue is a single entry in the U knot list// vKnotCount is the size of the V knot list// vKnotValue is a single entry in the V knot list// If TRIMis specified then additional trim information is expected// If NOTRIMis specified then the surface is not trimmed// cvCount is the number of CVs in the surface// xCVValue,yCVValue,zCVValue [wCVValue]is a single CV.// zCVValue is only present when dimension is 3.// wCVValue is only present when isRational is true//setAttr node.surfaceAttr -type nurbsSurface 3 3 0 0 no 6 0 0 0 1 1 16 0 0 0 1 1 116 -2 3 0 -2 1 0 -2 -1 0 -2 -3 0-1 3 0 -1 1 0 -1 -1 0 -1 -3 01 3 0 1 1 0 1 -1 0 1 -3 03 3 0 3 1 0 3 -1 0 3 -3 0;-type nurbsTrimfaceNURBS trim face dataValue SyntaxValue MeaningExample// flipNormal if true turns the surface inside out// boundaryCount: number of boundaries// boundaryType: // tedgeCountOnBoundary : number of edges in a boundary// splineCountOnEdge : number of splines in an edge in// edgeTolerance : tolerance used to build the 3d edge// isEdgeReversed : if true, the edge is backwards// geometricContinuity : if true, the edge is tangent continuous// splineCountOnPedge : number of splines in a 2d edge// isMonotone : if true, curvature is monotone// pedgeTolerance : tolerance for the 2d edge//-type polyFacePolygon face dataValue SyntaxfhmfmhmufcValue MeaningfhmfmhmufcExample// This data type (polyFace) is meant to be used in file I/O// after setAttrs have been written out for vertex position// arrays, edge connectivity arrays (with corresponding start// and end vertex descriptions), texture coordinate arrays and// color arrays. The reason is that this data type references// all of its data through ids created by the former types.//// fspecifies the ids of the edges making up a face -// negative value if the edge is reversed in the face// hspecifies the ids of the edges making up a hole -// negative value if the edge is reversed in the face// mfspecifies the ids of texture coordinates (uvs) for a face.// This data type is obsolete as of version 3.0. It is replaced by mu.// mhspecifies the ids of texture coordinates (uvs) for a hole// This data type is obsolete as of version 3.0. It is replaced by mu.// muThe first argument refers to the uv set. This is a zero- based// integer number. The second argument refers to the number of vertices (n)// on the face which have valid uv values. The last n values are the uv// ids of the texture coordinates (uvs) for the face. These indices// are what used to be represented by the mfand mhspecification.// There may be more than one muspecification, one for each unique uv set.// fcspecifies the color index values for a face//setAttr node.polyFaceAttr -type polyFaces f3 1 2 3 fc3 4 4 6;-type meshPolygonal meshValue SyntaxValue Meaningvvn[vtesmooth|hard]Example// vspecifies the vertices of the polygonal mesh// vnspecifies the normal of each vertex// vtis optional and specifies a U,V texture coordinate for each vertex// especifies the edge connectivity information between vertices//setAttr node.meshAttr -type mesh v3 0 0 0 0 1 0 0 0 1vn3 1 0 0 1 0 0 1 0 0vt3 0 0 0 1 1 0e3 0 1 hard1 2 hard2 0 hard;-type latticeLattice dataValue SyntaxValue MeaningsDivisionCount tDivisionCount uDivisionCountExample// sDivisionCount is the horizontal lattice division count// tDivisionCount is the vertical lattice division count// uDivisionCount is the depth lattice division count// pointCount is the total number of lattice points// pointX,pointY,pointZ is one lattice point. The list is// specified varying first in S, then in T, last in U so the// first two entries are (S=0,T=0,U=0) (s=1,T=0,U=0)//setAttr node.latticeAttr -type lattice 2 5 2 20-2 -2 -2 2 -2 -2 -2 -1 -2 2 -1 -2 -2 0 -22 0 -2 -2 1 -2 2 1 -2 -2 2 -2 2 2 -2-2 -2 2 2 -2 2 -2 -1 2 2 -1 2 -2 0 22 0 2 -2 1 2 2 1 2 -2 2 2 2 2 2;In query mode, return type is based on queried flag.
No need to set type, this will automatically be determined
Adds support for passing a list or tuple as the second argument for datatypes such as double3.
When setting stringArray datatype, you no longer need to prefix the list with the number of elements - just pass a list or tuple as with other arrays
if no type flag is passed, the attribute type is based on type of value being set (if you want a float, be sure to format it as a float, e.g. 3.0 not 3)
currently does not support compound attributes
currently supported python-to-maya mappings:
python type maya type ============ =========== float double ———— ———– int long ———— ———– str string ———— ———– bool bool ———— ———– Vector double3 ———— ———– Matrix matrix ———— ———– [str] stringArray ============ ===========
>>> addAttr( 'persp', longName= 'testDoubleArray', dataType='doubleArray')
>>> setAttr( 'persp.testDoubleArray', [0,1,2])
>>> setAttr( 'defaultRenderGlobals.preMel', 'sfff')
Added ability to set enum attributes using the string values; this may be done either by setting the ‘asString’ kwarg to True, or simply supplying a string value for an enum attribute.
Long name (short name) | Argument Types | Properties | |
---|---|---|---|
alteredValue (av) | bool | ||
The value is only the current value, which may change in the next evalution (if the attribute has an incoming connection). This flag is only used during file I/O, so that attributes with incoming connections do not have their data overwritten during the first evaluation after a file is opened. |
|||
caching (ca) | bool | ||
Sets the attribute’s internal caching on or off. Not all attributes can be defined as caching. Only those attributes that are not defined by default to be cached can be made caching. As well, multi attribute elements cannot be made caching. Caching also affects child attributes for compound attributes. |
|||
channelBox (cb) | bool | ||
|
|||
clamp (c) | bool | ||
For numeric attributes, if the value is outside the range of the attribute, clamp it to the min or max instead of failing Flag can have multiple arguments, passed either as a tuple or a list. |
|||
keyable (k) | bool | ||
|
|||
lock (l) | bool | ||
|
|||
size (s) | int | ||
|
|||
type (typ) | unicode | ||
|
Derived from mel command maya.cmds.setAttr
Example:
import pymel.core as pm
pm.sphere( n="sphere" )
# Result: [nt.Transform(u'sphere'), nt.MakeNurbSphere(u'makeNurbSphere1')] #
# Set a simple numeric value
pm.setAttr( 'sphere.translateX', 5 )
# Lock an attribute to prevent further modification
pm.setAttr( 'sphere.translateX', lock=True )
# Make an attribute unkeyable
pm.setAttr( 'sphere.translateZ', keyable=False )
# Set an entire list of multi-attribute values in one command
pm.setAttr( 'sphereShape.weights[0:6]',1, 1, 2, 1, 1, 1, 2,size=7)
# Set an attribute with a compound numeric type
pm.setAttr('sphere.rotate', 0, 45, 90, type="double3")
# Clamp the value of the attribute to the min/max
# Useful floating point math leaves the value just
# a little out of range - here the min is .01
pm.setAttr( 'anisotropic1.roughness', 0.0099978, clamp=True )
# Set a multi-attribute with a compound numeric type
pm.setAttr( 'sphereShape.controlPoints[0:2]', 0, 0, 0, 1, 1, 1, 2, 2, 2,type="double3" )