8
$\begingroup$

I want to append an element from another Blend file by a script. I found the Blender operator bpy.ops.wm.append which should do what I want. However, the API documentation is a bit unclear:

filepath  – File Path, Path to file
directory – Directory, Directory of the file
filename  – File Name, Name of the file

So what exactly is expected here?

$\endgroup$
0

1 Answer 1

15
$\begingroup$

After trying out the interface for a while, i finally found the values that seem to satisfy the API. Here is a code snippet:

blendfile = "D:/path/to/the/repository.blend"
section   = "\\Action\\"
object    = "myaction"

filepath  = blendfile + section + object
directory = blendfile + section
filename  = object

bpy.ops.wm.append(
    filepath=filepath, 
    filename=filename,
    directory=directory)

Hint: The directroy string must be terminated with a trailing "\\". If you do not do that, then you always get an error "not a library". I also found that you only need to supply filename and directory, which makes some sense:

bpy.ops.wm.append(filename=filename, directory=directory) # works

However this does not work, no idea why:

bpy.ops.wm.append(filepath=filepath) # does not work (why that?) 
$\endgroup$
4
  • 1
    $\begingroup$ Is there a way to append multiple objects at once? I tried giving filename as '*', '', without filename argument. But nothing seems to work. $\endgroup$
    – Anurag
    Commented Mar 21, 2016 at 13:31
  • 2
    $\begingroup$ Just a small addition. I am using this in Blender 2.76b. section = "/Action/" works for me while "\\Action\\". The latter does not throw any error but just doesn't append anything $\endgroup$
    – Sum-Al
    Commented Jun 17, 2016 at 7:29
  • $\begingroup$ @anurag Yes, we can append multiple objects at once. You need to group them together in the source blender file, append the group in the new Blender file and then unlink the group. $\endgroup$
    – Sum-Al
    Commented Jun 22, 2016 at 13:42
  • $\begingroup$ +1 for (filename=filename, directory=directory) # works and (filepath=filepath) # does not work (why that?) $\endgroup$ Commented Dec 27, 2016 at 20:42

Not the answer you're looking for? Browse other questions tagged .