Where in the API can I change positiion/rotation of the selected camera?

I want to write an add-on that will change the position and rotation of the selected camera on the fly. What code would I use to call this?

Note that I will want to first check whether the selected object is indeed a camera object before changing the position and rotation. There can be multiple cameras in a scene.

Thanks!

import bpy

obj =bpy.data.scenes[0].objects[“Camera”]

then you can rotate or re locate it as an object
but how using what ?

but not certain what you mean by on the fly !

happy bl

To check if it’s a camera or not, use object.type == ‘CAMERA’

Thanks for both of your responses. How do I find out what the selected object is in a scene, though? There’s no guarantee that the camera is going to be called “Camera”. (Of course, I realize multiple objects can be selected – in that case, I just want to look at the first selected object that I find.)



import bpy
obj_act= bpy.context.active_object 
 print('Active object =', obj_act )


 and for selected


 import bpy 
 sel_objects = bpy.context.selected_objects 

 for obj in sel_objects:
     print ('obj type =', obj.type,' name =', obj.name )


happy bl

Got it – thanks, everybody!