5
$\begingroup$

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?

$\endgroup$
2
  • $\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, 2014 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, 2014 at 9:56

1 Answer 1

7
$\begingroup$

There is some archaic way you could do this with bpy.ops.wm.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:
        print(mat.name)

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.

$\endgroup$

You must log in to answer this question.

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