|09 September 2017|
Python Maya Script : Create Cube as same distance between them along a circle shape
I am trying to write a script that create multiple cube and place them at the same distance from the origin. I want them to create a circle with cube and i want those cubes to be at the same distance between them.
I only succed to create cube at them distance from origin but no at the same distance between them.
Here is my script.
import maya.cmds as cm
cubeList = 
for i in range(0,60):
cube = cm.polyCube ()
for i in range(0,len(cubeList)):
angle = i * (360/(i+1))
x = 10*math.cos(angle)
y = 10*math.sin(angle)
Can someone help me ?
|10 October 2017|
Something along these lines should work.
from maya import cmds, OpenMaya
def main(count, radius, up_axis=(0, 1, 0)):
up_axis = OpenMaya.MVector(*up_axis).normal()
cubes = 
angle_increment = 360.0 / count
for i in xrange(count):
# Create a cube.
cube = cmds.polyCube()
# Get an axis perpendicular to the up-axis to set the initial position.
x_axis = OpenMaya.MVector(1, 0, 0)
if x_axis.angle(up_axis) > 0.01:
point = (x_axis ^ up_axis) * radius
point = (OpenMaya.MVector(0, 1, 0) ^ up_axis) * radius
# Rotate The point by the angle increment around the up-axis.
angle = angle_increment * i
quat = OpenMaya.MQuaternion(math.radians(angle), up_axis)
point = point.rotateBy(quat)
# Set the cube's position.
cmds.xform(cube, translation=(point.x, point.y, point.z), worldSpace=True)
cubes = main(10, 5, (0, 10, 0))
|reply share thread|