help by rotating simple object

i found the piece of code below to move an object around and works pretty good. but what i would like to do is rotate the cube around its own axis, i have googled for solution but it vain , the function applyRotation didn’t work, rot. also didn’t work, rotation_euler same thing, what i’m looking for is something like ob.rotation instead of the ob.location so if someone know how to solve this , i would be very thankful.

code sample:

import bpy
import math

if not ‘Cube’ in

frames_per_revolution = 120.0
step_size = 2*math.pi / frames_per_revolution

def set_object_location(n):
x = math.sin(n) * 5
y = math.cos(n) * 5
z = 0.0
ob =“Cube”)
ob.location = (x, y, z) # something like ob.rotation

every frame change, this function is called.

def my_handler(scene):
frame = scene.frame_current
n = frame % frames_per_revolution

if n == 0:

In what way rotation_euler doesn’t work ? When I do this :

ob.rotation_euler.x = 45

it works.

But be carefull, rotation in Blender is not a simple tuple of values like location. You can express it in quaternion, in rotation axis or in several euler forms (according to the order the axis are rotated, XYZ by default). You can explore the different options in the Transform sub-panel (top of the right panel in 3D scene, press N to open it). If you want to animate it, be aware that the object will display the transform selected in the drop-down list below the Rotation datas. So, if for example “Quaternion” is selected in this panel and you change rotation_euler, nothing will change in the scene because your object will reflect the orientation defined by rotation_quaternion. You can programmatically change the option by changing rotation_mode. So, to ensure for example that your object will display the rotation you’ve modified, try this :

ob.rotation_mode = "XYZ"
ob.rotation_euler.x = 45

note that rotations are in radians, if you wanna rotate by 45 degrees, use radians(45)

Oops, that’s right, rotations in Blender are in radians (except for quaternions if you’re not familiar with them, they doesn’t work like that).