.setAttr() – Setting Maya object attributes with Python

Set an attribute of an object:

# Import the Maya commands
from maya import cmds

# Create a cube list
cube = cmds.polyCube()

# Select the cube object
cubeShape = cube[0]

# Lock the translate attribute
cmds.setAttr(cubeShape+".translate", lock=True)

# Lock the rotate attribute
cmds.setAttr(cubeShape+".rotate", lock=True)

# Lock the scale attribute
cmds.setAttr(cubeShape+".scale", lock=True)

# Select the object
cmds.select(cubeShape)