Rotating an Object

Dear Reader,

question of a Blender newby.
how do i rotate an object with python, trying to build a script that gives me a 3point lighting setup and need to rotate the rimlight

rimLight_object.location = (xRimLight, yRimLight, zRimLight)
#rimLight_object.transform.rotate = (-90, 0, 0)
#rimLight_object.transform.rotation = (-90, 0, 0)
#rimLight_object.rotate(value=-0.261911, orient_axis='Z')
#rimLight_object.rotation(value=-0.261911, orient_axis='Z')
#rimLight_object.rotation = (-90, 0, 0)
#rimLight_data.rotation = (-90, 0, 0)
#rimLight_data.rotate = (-90, 0, 0)

1 Like

If you want to rotate the active object along an axis use this:

bpy.ops.transform.rotate(value=0.349066, orient_axis=“Z”)

If you want to set the rotation for an object use this:


rimLight.rotation_euler = (x, y, z)

The xyz values need to be in radians, so if you want to convert the values from degrees do it like this:

from math import radians
rimLight.rotation_euler = (radians(90), 0, 0)

Does this answer your question?

after some long google searches i found this… and its working for my case…
thank you for your attempt… but it was not working…
it seems the rotation command in 2.8 is not rotation, but rotation_euler, and indeed, it needs to be set in radians

rimLight_object.rotation_euler = (math.radians(-90), 0, 0)

my light is not the active object cause i create objects in a script and then add specs to it…
i first create data nodes, then the objects

rimLight_data ="data_RimLight", type='SPOT') = 50000
rimLight_object ="pLight_RimLight", object_data=rimLight_data)
rimLight_object.location = (xRimLight, yRimLight, zRimLight)
rimLight_object.rotation_euler = (math.radians(-90), 0, 0)

Oh yes, sorry I simply forgot that right after I tried it in blender… :smile: I’ll edit it in my original post to avoid confusion for other people who look at this