1. Set object attributes and read object attributes (setAttr & getAttr)
Code:
import maya.cmds
lco = maya.cmds.spaceLocator()[0] #创建定位器
#Get attributes
sx = maya.cmds.getAttr(lco+ ".scaleX")
print(sx)
#Set attributes
sx*= 2
maya.cmds.setAttr(lco+".scaleX")
2. Set the connection attribute (connectAttr & disconnectAttr)
code:
import maya.cmds
sphere = maya.cmds.polySphere()[0]
cube = maya.cmds.polyCube()[0]
#Connect the y-axis rotation property of the cube to the y-axis movement property of the sphere
maya.cmds.connectAttr(cube + ".ry",sphere + ".ty")
maya.cmds.select(cube)
#Disconnect attribute
maya.cmds.disconnectAttr(cube + ".ry" , sphere + ".ty")