How to link/append with a Python script? [duplicate]

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?

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?)

• Is there a way to append multiple objects at once? I tried giving filename as '*', '', without filename argument. But nothing seems to work. – Anurag Mar 21 '16 at 13:31
• 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 – Sum-Al Jun 17 '16 at 7:29
• @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. – Sum-Al Jun 22 '16 at 13:42
• +1 for (filename=filename, directory=directory) # works and (filepath=filepath) # does not work (why that?)  – Sibbs Gambling Dec 27 '16 at 20:42