Is it possible to import an object from a library file through Python without using bpy.ops.wm.link_append
? I want an object to appear in bpy.data.objects
without updating current scene.
2 Answers
$\begingroup$
$\endgroup$
1
Since Blender 2.72, there are two separate operators:
bpy.ops.wm.link()
bpy.ops.wm.append()
Apart from operators, there's also a lower-level API to import datablocks (selectively) from .blends: bpy.data.libraries.load()
The docs include a few examples how you can use this function.
-
$\begingroup$ +1. It seems that
bpy.ops.wm.link()
doesn't support wildcard (blender.stackexchange.com/questions/69985/…)? As a workaround, I used the code by @der_die_das_jojo, but that actually appends everything over, although the name isscn.objects.link()
... Any better ideas? $\endgroup$ Commented Dec 27, 2016 at 23:35
$\begingroup$
$\endgroup$
1
Here is an example how to use bpy.data.libraries.load() and link it to current scene
import bpy
scn = bpy.context.scene
filepath = "D:\\File.blend"
#append object from .blend file
with bpy.data.libraries.load(filepath) as (data_from, data_to):
data_to.objects = data_from.objects
#link object to current scene
for obj in data_to.objects:
if obj is not None:
scn.collection.objects.link(obj)
-
$\begingroup$ I often get
EXCEPTION_ACCESS_VIOLATION
on line:scn.objects.link(obj)
. It occurs randomly but almost on every other attempt. $\endgroup$– Logic1Commented Jul 14, 2018 at 4:43