I have created a cube using python in blender
bpy.ops.mesh.primitive_cube_add(radius=1, location=(x, y, z))
I want to rotate the cube around its z-axis with a random angle between -180, 180 degrees. Is there an argument or do I need a new line of code? How do i accomplish this?
Thanks!
You can add a rotation argument to
primitive_cube_Add. Note that python rotation options use radians, so you may need to usemath.radians(x)You can also directly change the rotatation of the object after you have created it. After
primitive_cube_add()the new object is selected and is the active object.While the above example works it is more correct to specify the rotation using a
mathutils.Eulerormathutils.Quaternionobject.