Hey all, I’m having a unexpected hard time trying to rotate a (selected) object using python in blender 2.53. The bpy.ops.transform.rotate() just rotates it on the z axis with Euler values (but i’d love for it work on all axis and in degrees). Must be missing something simple right?
Help would be great!
Update: managed to get a bit closer using the constraint_axis arguments, but still feel like there is sure to be an easier way to do this.
Several things.
import math and use math.radians …
there are a lot of options which I do not know exactly
using constraint_axis=(True, True, True) with … seemed to fulfill your wish (not only z-axis)
The Cube (i tested with) was rotated not to the z-Axis alone but some other screw axis
(unimportant).
goto the Scripting and have a look here http://www.blender.org/documentation/blender_python_api_2_54_0/bpy.ops.transform.html
An alternative… I’d say, don’t use the ops, but in stead set the rotation_euler of the object.
So something more like:
import bpy, math
# Get the active object
ob = bpy.context.active_object
# Set the x rotation of the active object (x y z) using the math radians function to convert from degrees to radians
ob.rotation_euler = [math.radians(30.0), 0.0, 0.0]
That helps. I did figure out that the constrain_axis was involved in some devious way, but I expected there to be some simple way like ; ob.rotation = (45.0, 90.0, 0.0) )as its so simple with location)