# How do I set my camera rotation with Python?

I'm working on an automatic renderer script, and I have some trouble setting the rotation of my camera. I suspect it has something to do with the need for me to convert the rotation values I want to quaternion values. The problem is that I am absolutely hopeless in maths and not very advanced in programming, I'm still learning. I have been looking on the internet but I have found very complex things such as this :

But I don't know where to start, I don't get what the code means and I don't know how to implement that to my case, so I figured it was best to ask from scratch.

SO basically I want my camera to have the same rotation I have created manually, that is to say : x= 66.9 y= 0 z= 28.9

Here's the last thing I have tried:

import bpy
import os
import math
import shutil
import glob
import bmesh
import mathutils

#Camera position
Camera = bpy.data.objects["Camera"]

pos= [24.408, -39.401, 33.853]
rot= [66.9, -0.000115, 28.9]

Camera.location.x = pos
Camera.location.y = pos
Camera.location.z = pos

Camera.rotation_mode = 'XYZ'
Camera.rotation_euler = rot
Camera.rotation_euler = rot
Camera.rotation_euler = rot

Camera.rotation_euler.to_quaternion()


And errr.... it doesn't work at all lol, it puts my camera at 3833° X, -0.00661° Y and 1656° Z...

Can someone help me ?

Thank you so much :)

• important to note blender uses radians as its internal measure of angle. When you orbit 2pi radians around a circle you have walked the perimeter. In your question code for example cam.rotation_euler = [math.radians(r) for r in rot] is another way to convert. – batFINGER Aug 31 '18 at 19:03
• Thanks batFINGER, your solution works as well! – Popi Sep 5 '18 at 8:25

def setupCamera(scene, c):
pi = math.pi

scene.camera.rotation_euler = c * (pi / 180.0)
scene.camera.rotation_euler = c * (pi / 180.0)
scene.camera.rotation_euler = c * (pi / 180.0)

scene.camera.location.x = c
scene.camera.location.y = c
scene.camera.location.z = c

return

scene = bpy.data.scenes["Scene"]

config = list([67.1349, 0.779594, 148.858, 5.57961, 9.16202, 5.34536])