0
$\begingroup$

I've been looking around the forums on here and BlenderArtists, as well as the Blender API documentation to try and create a script that suites my needs. This is as far as I got, though it doesn't work, I hope someone can at least see what I am trying to accomplish?

Basically I have multiple furniture assets that come in a variety of colors, instead of manually replacing each material and saving it out with a specific naming by hand, I want to try and automate it as it's very repetitive.

I have an asset with a default material that needs to be replaced by appending materials from other .blend files that I have saved in a different location, then save that blend file with the new material's name. And then loop through this command until it's finished through the given materials to replace.

Here is my sad attempt at trying to do it myself..

import bpy 

Asset_Name = Wylie_Chest

library_path = 
{
'//Falcon_Grey_Lacquer.blend'
'//Boeing_Navy_Lacquer.blend'
'//Charter_Coral_Lacquer.blend'
}

    #Append Not Link
link = False

    #Load Materials From New Library
with bpy.data.libraries.load(library_path, link=link) as (data_from, data_to):
    data_to.materials = data_from.materials
    
    #Stating Old Material And New Materials
old_mat = bpy.data.materials.get('Cirrus_White_Lacquer')
new_mat = bpy.data.materials.get('Boeing_Navy_Lacquer')
new_mat = bpy.data.materials.get('Charter_Coral_Lacquer')
new_mat = bpy.data.materials.get('Falcon_Grey_Lacquer')
old_mat.user_remap(new_mat)

    #Execute Replacing Old Material With New Materials
for name, mat in old_mat():
    new_mat = bpy.data.materials.get(name)
    if new_mat is None:
        mat.name = name

    #Purge Old Materials
bpy.ops.outliner.orphans_purge()

    #Save .blend With New Material Name
bpy.context.space_data.params.filename = ''Asset_Name'+'new_mat'+'Brushed_Bronze_SmSqHandle'+'.blend''
$\endgroup$

Your Answer

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

Browse other questions tagged or ask your own question.