I am importing FBX files that have camera placeholders. They will import as Empty's in blender that may have useful animation. I want to add add a camera to each as a child (inherit animation) and align the view to the placeholder's alignment, parent it, and add a TRACK_TO constraint if there is a "cameraName.Target" Empty placeholder.


The following is an example script that worked for me. I first (manually) created a collection named "cameras" and moved all the Empties into that collection. I skip any existing cameras in case I run the script more than once.

import bpy

for obj in bpy.data.objects:
    hasACamera = False
    if ( ("Camera" in obj.name) and ("Target" not in obj.name) and (obj.type != 'CAMERA') ):
        for child in obj.children:
            if (child.type == 'CAMERA'):
                hasACamera = True
        if ( hasACamera is True ):
            print( obj.name + ": already has a camera")
        print( obj )
        print( obj.type )
        bpy.context.object.name = obj.name + ".Camera"
        print( bpy.context.object )
        print( bpy.context.active_object )
        sel = bpy.data.objects[bpy.context.object.name]
        print( sel.name + " align"  )
        bpy.ops.transform.transform(mode='ALIGN', value=(0, 0, 0, 0), orient_type='GLOBAL',
         orient_matrix=((1, 0, 0), (0, 1, 0), (0, 0, 1)), orient_matrix_type='GLOBAL', mirror=True, use_proportional_edit=False,
         proportional_edit_falloff='SMOOTH', proportional_size=1, use_proportional_connected=False, use_proportional_projected=False)
        sel.parent = obj
    if ( (obj.type == 'CAMERA') and (".Camera" in obj.name) ):
        targetName = obj.name[0:-7] + ".Target"
            targetObj = bpy.data.objects[targetName]
            if obj.constraints["Track To"] is None:
                print( "adding Track To constraint" )
                obj.constraints["Track To"].target = targetObj

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.