import bpy

# Paths to assets
logo_path = "/mnt/c/Users/Jeff/logo_effects/logo2.png"
santa_path = "/mnt/c/Users/Jeff/logo_effects/SantaModel.blend"
tree_path = "/mnt/c/Users/Jeff/logo_effects/tree.blend"

# Scene setup
def clear_scene():
    """Clear all objects in the scene."""
    bpy.ops.object.select_all(action='SELECT')
    bpy.ops.object.delete(use_global=False)

def import_logo():
    """Import the logo as a plane."""
    try:
        # Use the full path for the logo
        bpy.ops.import_image.to_plane(filepath=logo_path)
        logo = bpy.context.object
        logo.name = "Logo"
        logo.scale = (2, 2, 1)  # Adjust size if needed
        logo.location = (0, -3, 0)  # Place logo in the background
        return logo
    except Exception as e:
        print(f"Error importing logo: {e}")
        return None

def import_model(file_path, name_filter):
    """Append a model from a Blender file."""
    with bpy.data.libraries.load(file_path, link=False) as (data_from, data_to):
        data_to.objects = [obj for obj in data_from.objects if name_filter.lower() in obj.lower()]
    for obj in data_to.objects:
        if obj is not None:
            bpy.context.scene.collection.objects.link(obj)
    return data_to.objects

def setup_animation(santa, tree, logo):
    """Animate Santa dragging a tree and setting it up by the logo."""
    # Place Santa and the tree at the start
    santa.location = (-5, 0, 0)
    tree.location = (-5, -0.5, 0)
    tree.rotation_euler = (0, 0, 1.5)  # Tilted as if dragging
    
    # Add keyframes for animation
    santa.keyframe_insert(data_path="location", frame=1)
    tree.keyframe_insert(data_path="location", frame=1)
    
    # Animate Santa walking to the logo
    santa.location = (0, 0, 0)
    tree.location = (0, -0.5, 0)
    santa.keyframe_insert(data_path="location", frame=60)
    tree.keyframe_insert(data_path="location", frame=60)
    
    # Animate Santa setting up the tree
    tree.location = (2, 0, 0)
    tree.rotation_euler = (0, 0, 0)  # Upright position
    tree.keyframe_insert(data_path="location", frame=90)
    tree.keyframe_insert(data_path="rotation_euler", frame=90)

def setup_scene():
    """Main setup function."""
    clear_scene()
    
    # Import assets
    logo = import_logo()
    if not logo:
        print("Failed to import logo. Aborting setup.")
        return

    santa_objects = import_model(santa_path, "Santa")
    if not santa_objects:
        print("Failed to import Santa. Aborting setup.")
        return
    santa = santa_objects[0]

    tree_objects = import_model(tree_path, "Tree")
    if not tree_objects:
        print("Failed to import tree. Aborting setup.")
        return
    tree = tree_objects[0]

    # Setup animation
    setup_animation(santa, tree, logo)

    # Add camera
    bpy.ops.object.camera_add(location=(0, -10, 5))
    camera = bpy.context.object
    bpy.context.scene.camera = camera
    camera.rotation_euler = (1.1, 0, 0)

    # Add lighting
    bpy.ops.object.light_add(type='SUN', location=(5, -5, 10))
    light = bpy.context.object
    light.data.energy = 10

    # Set render settings
    bpy.context.scene.render.resolution_x = 1024
    bpy.context.scene.render.resolution_y = 1024
    bpy.context.scene.render.film_transparent = True

# Run the scene setup
setup_scene()

# Save the scene
output_path = "/mnt/c/Users/Jeff/logo_effects/santa_scene.blend"
bpy.ops.wm.save_as_mainfile(filepath=output_path)
print(f"Scene saved at {output_path}")
Paths:

Ensure that the paths to logo2.png, SantaModel.blend, and tree.blend are correct and accessible.
Model Import:

The import_model function uses a substring match (name_filter) to find objects within the Blender files. Replace "Santa" and "Tree" with actual names or part of names from the .blend files.
Animation:

Santa starts off-screen, drags the tree to the logo, and then sets it up upright beside the logo.
Camera and Lighting:

A camera and a sun lamp are added to frame and light the scene.
Saving:

The script saves the final .blend file in the same directory as your assets.
To Run the Script
Open Blender.
Go to the Scripting workspace.
Open create_santa_scene.py.
Click Run Script.