How do I import an image as a plane after opening a new .blend file? In my script, I'm trying to open a new .blend file, then create a new plane and attach an image to that. I can run the script to create a plane mesh and successfully attach an image to that, but if I preface to that script the opening of a new blender file, I lose that ability. Here is a stripped-down version of my code rearranged so that it exposes the problem:

# Imports.
from bpy import context, ops
import os

# Demonstrate that you can attach an image to a plane.
ops.mesh.primitive_plane_add()
plane = context.scene.objects.active
plane.data.uv_textures.new()
if len(plane.data.uv_textures[0].data) &gt; 0:
    print('We have UV Texture data')
else:
    print("We don't have UV Texture data")

# Where to get blender files.
blender_file_dir = 'D:\\Path\\to\\blend\\data\\folder'

# Object class.
object_name = 'CoDrone'

# Open blender file (needs to match the object name).
filepath = os.path.join(blender_file_dir, '{}.blend'.format(object_name))
ops.wm.open_mainfile(filepath=filepath)

# Demonstrate that you can no longer attach an image to a plane
ops.mesh.primitive_plane_add()
plane = context.scene.objects.active
plane.data.uv_textures.new()
if len(plane.data.uv_textures[0].data) &gt; 0:
    print('We have UV Texture data')
else:
    print("We don't have UV Texture data")


Running the above code gets this output:

We have UV Texture data
Read blend: D:\Path\to\blend\data\folder\CoDrone.blend
We don't have UV Texture data
With hints from @rob that it's better to append the scene and destroy the old one, and code from How to delete a scene with its content? to destroy the objects in the old scene first, I finally got the results I expected. When you run this code:

# Imports.
from bpy import context, ops, data
import os
import random

def delete_scene_objects():

    # Get the current scene.
    scene = context.screen.scene

    # Remove objects.
    for object_name in scene.objects:
        data.objects.remove(object_name, True)

    return scene

def add_plane():
    ops.mesh.primitive_plane_add()
    plane = context.scene.objects.active

    # Add a UV texture layer to the mesh.
    plane.data.uv_textures.new()

    # Demonstrate that you can attach an image to the mesh.
    if len(plane.data.uv_textures[0].data) &gt; 0:
        print('We have UV Texture data')
    else:
        print("We don't have UV Texture data")

def append_blend_file(blend_file):
    section_name = '\\Scene\\'
    object_name = 'Scene'

    directory_name = blend_file + section_name
    ops.wm.append(filename=object_name, directory=directory_name)

def add_blend_file():

    # Where to get blender files.
    blender_file_dir = 'D:\\Path\\to\\blend\\data\\folder'

    # Object class.
    class_name = 'CoDrone'

    # Open blender file (needs to match the object name).
    file_name = '{}.blend'.format(class_name)
    blend_file = os.path.join(blender_file_dir, file_name)
    append_blend_file(blend_file)

add_plane()
old_scene = delete_scene_objects()
add_blend_file()

# Remove old scene.
data.scenes.remove(old_scene, True)

add_plane()


You get this output:

We have UV Texture data
We have UV Texture data