0
$\begingroup$

I am trying to set the camera rotation to 0,0,0. It is not known in advance what the X,Y,Z rotation angles are before doing so.

My thought is to get the current rotation parameters using obj.rotation_euler and then doing a reverse rotation on each of the axes.

For some reason, the transform.rotate code below doesn't actually do anything.

Thanks in advance for your help!

obj=bpy.data.objects['Camera']    
objrot=obj.rotation_euler
bpy.ops.transform.rotate(value=-objrot[0], orient_axis='X', orient_type='GLOBAL', orient_matrix=((1, 0, 0), (0, 1, 0), (0, 0, 1)), orient_matrix_type='GLOBAL', constraint_axis=(False, True, False), mirror=True, use_proportional_edit=True, proportional_edit_falloff='SMOOTH', proportional_size=1, use_proportional_connected=False, use_proportional_projected=False)
bpy.ops.transform.rotate(value=-objrot[1], orient_axis='Y', orient_type='GLOBAL', orient_matrix=((1, 0, 0), (0, 1, 0), (0, 0, 1)), orient_matrix_type='GLOBAL', constraint_axis=(False, True, False), mirror=True, use_proportional_edit=True, proportional_edit_falloff='SMOOTH', proportional_size=1, use_proportional_connected=False, use_proportional_projected=False)
bpy.ops.transform.rotate(value=-objrot[2], orient_axis='Z', orient_type='GLOBAL', orient_matrix=((1, 0, 0), (0, 1, 0), (0, 0, 1)), orient_matrix_type='GLOBAL', constraint_axis=(False, True, False), mirror=True, use_proportional_edit=True, proportional_edit_falloff='SMOOTH', proportional_size=1, use_proportional_connected=False, use_proportional_projected=False)
$\endgroup$
1
  • 1
    $\begingroup$ Martin's answer is the way to go. Note that setting camera rotationn to 0,0,0 means it will point straight down (i.e. looking negatively along the Z-axis) $\endgroup$
    – Moog
    Sep 14, 2019 at 20:34

1 Answer 1

1
$\begingroup$

bpy.context.scene.camera.rotation_euler = (0,0,0)

$\endgroup$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .