Hi, i want to catch the event of object selection to run a especific funtion.
Everytime i select an object i want to run the function.
Here is the code:
import bpy
def swapCamera():
context = bpy.context
scene = context.scene
currentCameraObj = bpy.data.objects[bpy.context.active_object.name+"_cam"]
scene.camera = currentCameraObj
class ChangeCameraRig(bpy.types.Operator):
bl_idname = "rig.change_camera"
bl_label = "Change Camera Rig"
@classmethod
def poll(self, context):
try:
ob = context.active_object
mode = context.mode
name = ob.name
return ( mode == "POSE" )
except AttributeError:
return 0
def execute(self, context):
swapCamera()
return {'FINISHED'}
def register():
bpy.utils.register_class(ChangeCameraRig)
def unregister():
bpy.utils.unregister_class(ChangeCameraRig)
if __name__ == "__main__":
register()
bpy.ops.rig.change_camera()
Thanks!