# Python Beginer - Rotate An Object Via Python Code

Hi All,
I have looked and looked and can find no information on how to rotate the cube via python code.

``````
import Blender as B
NAME = 'Cube'      # Name of object to process.
ob = B.Object.Get( NAME )

``````

To position the cube, all I need to do is this.

``````
ob.setLocation(x,y,z)

``````

But to rotate the cube I don’t know what the syntax is to rotate?
I tried the obvious.

``````
ob.setRotation(45,23,90)

``````

But that didn’t work.

Why is this basic information so incredibly hidden an not documented? You’d think it would be listed as a property of Object.

Can anyone help with this?

Is it even possible to rotate a cube via python?

All right, I found a clue in another post about rotation.

It seems each object has a property called “RotX”, “RotY”, and “RotZ”.

You can assign degrees to these properties.

``````
ob.RotX = 45

``````

Ok, so how do I convert from degrees to radians to I can rotate my cube at 23 degrees?

I know it is a simple math library call, but I do no know the syntax.

In other languages, it is something like rad2deg.

Does python have this in it’s math library?

if v is an angle in degrees, you get this angle in radians like this:

angle in radians = v * pi / 180

or if you want to do it with a function call, radians(v) converts the angle v, given in degrees, to radians (according to http://docs.python.org/lib/module-math.html, haven’t used it myself).

Thanks for the math!