1

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!

1

1 Answer 1

1

You can add a rotation argument to primitive_cube_Add. Note that python rotation options use radians, so you may need to use math.radians(x)

bpy.ops.mesh.primitive_cube_add(radius=1, location=(x,y,z), rotation=(rx,ry,rz))

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.

bpy.context.active_object.rotation_mode = 'XYZ'
bpy.context.active_object.rotation_euler = (rx, ry, rz)

While the above example works it is more correct to specify the rotation using a mathutils.Euler or mathutils.Quaternion object.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.