![maya python setattr of multiple objects maya python setattr of multiple objects](https://online-courses.club/wp-content/uploads/2021/06/Gnomon-Master-Rigging-Python-Scripting-In-Maya-864x450.png)
- MAYA PYTHON SETATTR OF MULTIPLE OBJECTS UPDATE
- MAYA PYTHON SETATTR OF MULTIPLE OBJECTS CODE
- MAYA PYTHON SETATTR OF MULTIPLE OBJECTS PLUS
StrandL,strandHistory = mc.polySphere(name=strandLName, ch=1)
![maya python setattr of multiple objects maya python setattr of multiple objects](https://odederell3d.blog/wp-content/uploads/2018/08/maya_python_frames.gif)
If I run it once it works, but the second time I get: Error: setAttr: Not enough data was provided.
MAYA PYTHON SETATTR OF MULTIPLE OBJECTS CODE
Now lets take a look at our code in its entirety: from maya import cmdsĬmds.setAttr(cubeShape+".translate", lock=True)Ĭmds.setAttr(cubeShape+".Trying to make a script I created be able to run multiple times. The add a little bonus in, when we run our code from the start we want to end up with the circle selected, so that we can immediately start to manipulate our object. However we can still move and manipulate the circle which will effect the cube as it is a child of the circle object.
![maya python setattr of multiple objects maya python setattr of multiple objects](https://i.stack.imgur.com/Fhwnz.png)
Now if we try to manipulate the cube in the viewport, we will not be able to. Lets go 1 step further and lock all of the basic position attributes (translate, rotate and scale) tAttr(cubeShape+".translate", lock=True)Ĭmds.setAttr(cubeShape+".rotate", lock=True)Ĭmds.setAttr(cubeShape+".scale", lock=True) Now let’s say we want to lock ALL of the translates, and not just the x or y value: tAttr(cubeShape+".translate", lock=True)
MAYA PYTHON SETATTR OF MULTIPLE OBJECTS PLUS
If we select and run the part we updated, you’ll see in the output that the string has been constructed using our variable name plus the translate y extension (.ty):
MAYA PYTHON SETATTR OF MULTIPLE OBJECTS UPDATE
We have already declared the variables cubeShape and circleShape which hold the objects, lets update the setAttr command to use the cubeShape variable: tAttr(cubeShape+".ty", lock=True) Lets go back to our original code: from maya import cmds We can change the attribute to translate y by updating the code to the following: tAttr("pCube2.ty", lock=True)īut hang on a second! If we are applying attributes using code, and we are already putting objects into variables, why don’t we apply the new attributes using the variable names rather than the objects directly: Lock=True = Set the lock attribute to true tx = The attribute we are changing (in this case translate x) PCube2 = The object to set the attribute of (We discovered this from the MEL output) SetAttr() = Set attribute method (expects values) While this command is accurate, its output in the MEL language, lets convert it to Python: tAttr("pCube2.tx", lock=True)Ĭmds = Use a maya command (imported in line 1) You’ll see that the command output has been updated with a command Now we are going to ‘lock’ the pCube’s attributes:Ĭlick on the pCube in the perspective panel (or top, side whatever)Īlt click on ‘Translate X’ and select ‘Lock Selected’: However you can still grab the pCube in the perspective view and move it independently from the nurbsCircle, lets see how we can fix this: This is great because if you move the nurbsCircle, the cube will move with it. Now run this command and we can see that the hierarchy has been updated in the outliner and the cube is now a child of the circle: The firstvalue is the child, and the secondis the parent (Give this child ‘cubeShape’ to its parent ‘circleShape’). So lets give this command something to chew on: cmds.parent(cubeShape, circleShape) If you run this alone you’ll get a ‘not enough object or values’ error, which makes sense as we need to define which objects we want to parent (this command expects2 values). To parent one object under the other we’ll use the parent command: cmds.parent() If we run this code, we should see a cube and a circle in the perspective viewport and the 2 objects in the outliner: Get the circle object from the 'circle' list Get the cube object from the 'cube' list Lets start with some code: // import the maya commands Let’s say we have 2 shapes (a cube and a circle), and we want to parent one shape under the other.