Currently, I'm working on a lot of files imported from Autodesk Maya to be rendered in Blender 2.8 EEVEE. And of course, the material looks bad when rendered. And will be a lot of work to fix all of these materials on every blend file by hand. So, I tried this python script to replace materials in the current file with the fixed one from other file:
import bpy scn = bpy.context.scene D = bpy.data filepath = '//10_rrd.blend' with bpy.data.libraries.load(filepath, link=False) as (data_from, data_to): data_to.materials = data_from.materials for mat in D.materials: for mat_fix in data_to.materials: if mat_fix.name == mat.name: print('Found a material copy for '+mat.name+' with name '+mat_fix.name) mat.diffuse_color = mat_fix.diffuse_color mat.metallic = mat_fix.metallic mat.roughness = mat_fix.roughness mat.specular_intensity = mat_fix.specular_intensity
The problem is:
Instead of replacing the properties of the material in current blend file, It appends the full material as a new material (with those '.001' suffix) in the current file without touching the materials that needs to be replaced.
What's wrong with my code? Is there is any fix? or should I stick with traditional way of replacing material of every object after it's appended?
By the way, It's not a problem of EEVEE.
bpy.data.libraries.load()...appends the material as a new one. Does it print your "Found a material..." in the console? $\endgroup$