I have many files containing different parts of my blender internal material collection. How can I make a script which imports all of them into another blend file?

  • $\begingroup$ This is easily possible without python. Do you need to use python? (I'm pretty sure it's possible with python too) Or is a gui solution acceptable? $\endgroup$ – gandalf3 May 14 '14 at 8:56
  • $\begingroup$ I would need to do it many times and on many files, and it would go nicely with the script i have already made. i know that you can press Shift+F1 to import from other blend files. It would need to be a python script. $\endgroup$ – Artmole May 14 '14 at 9:56

There is some archaic way you could do this with bpy.ops.wm.link_append() but a better way is to work with the api available via bpy.types.BlendDataLibraries.

import bpy

# using a relative path
path = "//file_name.blend"

with bpy.data.libraries.load(path) as (data_from, data_to):
    data_to.materials = data_from.materials

As a sanity check or for logging purposes, you can loop through what was appended and see if everything is there as it should be

for mat in data_to.materials:
    if mat is not None:

As it relates to many files, it should be simple enough to extend the script to also loop through a list of filenames to append materials from. A final note, the materials appended have no users so make sure to stick them somewhere before closing your file.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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