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 bpy.data.objects:
bpy.ops.mesh.primitive_cube_add()
def set_object_location(n):
x = math.sin(n) * 5
y = math.cos(n) * 5
z = 0.0
ob = bpy.data.objects.get(“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:
set_object_location(n)
else:
set_object_location(n*step_size)
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 :