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) > 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) > 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
ops.wm.link
I getRuntimeError: Error: 'D:\Path\to\blend\data\folder\CoDrone.blend': not a library
$\endgroup$ – Dave Babbitt Feb 15 '19 at 20:47