Trying to append a material from one blend file to another but not having any luck. I've tried two methods so far.
Method 1:
bpy.ops.wm.append(
filepath="material.blend",
directory="/Users/me/Desktop/Materials/material.blend\\Material\\",
filename="Material01")
In the console this returns {'FINISHED'} but there is no new material appended to my file.
Method 2:
# path to the blend
filepath = "/Users/me/Desktop/Materials/material.blend"
name of object(s) to append or link
mat_name = "material01"
append, set to true to keep the link to the original file
link = False
with bpy.data.libraries.load(filepath, link=link) as (data_from, data_to):
data_to.materials = [name for name in data_from.materials if name.startswith(mat_name)]
#link object to current scene
for mat in data_to.materials:
if mat is not None:
bpy.context.collection.materials.link(mat)
I read that this method is more appropriate, but again, nothing happens. Method 2 was originally written for objects in the example I saw, so is there maybe something I'm missing for materials?
Interestingly, after running either of these, when I go to manually append (file>append) my file explorer opens on the material I'm trying to append. So it is getting Blender to look at the right material, but not appending it.
Any help greatly appreciated!
CK