5
$\begingroup$

This question already has an answer here:

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$

marked as duplicate by ideasman42, p2or, PGmath, David Sep 5 '15 at 13:59

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

12
$\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$
  • $\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 Mar 21 '16 at 13:31
  • $\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 Jun 17 '16 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 Jun 22 '16 at 13:42
  • $\begingroup$ +1 for (filename=filename, directory=directory) # works and (filepath=filepath) # does not work (why that?) $\endgroup$ – Sibbs Gambling Dec 27 '16 at 20:42

Not the answer you're looking for? Browse other questions tagged or ask your own question.