maya的脚本是非常之强大的,参数化建模,智能设计师未来的一个趋势。
实现的功能:
import maya.cmds as cmds import random random.seed(1111) cubeList = cmds.ls('mycube*') if len(cubeList)>0: cmds.delete(cubeList) groupName = cmds.group(em=True,n='groupCube') for i in range(0,60): result = cmds.polyCube(w=1,h=1,d=1,n='mycube#') cmds.parent(result,groupName) x = random.uniform(-10,10) y = random.uniform(-10,10) z = random.uniform(-10,10) cmds.move(x,y,z,result) xRot = random.uniform(0,180) yRot = random.uniform(0,180) zRot = random.uniform(0,180) cmds.rotate(xRot,yRot,zRot,result) scaleFactor = random.uniform(0.8,1.2) cmds.scale(scaleFactor,scaleFactor,scaleFactor,result)
selectionList = cmds.ls(orderedSelection=True) print selectionList if len(selectionList)>=2: targetName = selectionList[0] selectionList.remove(targetName) for objectName in selectionList: cmds.aimConstraint(targetName,objectName,aim=[2.0,1.0,1.0]) else: print 'Select more than two objects!'