The words Under construction in black text on a yellow background with diagonal black stipes surrounding it
I'm in the process of moving my site. It's still a work in progress. Please excuse the mess and broken links.

Create A Blender Material With A Python Script

TODO: Pull subtitle into page object

** TL;DR

This Python script makes a basic "Principled BSDF" material in Blender. It takes an array a name for the material and an array of tuples for the settings

code_start_default_section code_end_default_section

Debugging Stuff

I'm moving stuff around right now. All this below is helping me figure out where to put stuff

        -- title

Create A Blender Material With A Python Script

-- p

** TL;DR

-- p

This Python script makes a basic "Principled BSDF" material in Blender. It takes an array a name for the material and an array of tuples for the settings

-- code/
-- python

import bpy


def create_material(name, params):
    if name not in bpy.data.materials:
        print(f"Making {name}")
        bpy.data.materials.new(name)
        material = bpy.data.materials[name]
        material.use_nodes = True
        for param in params:
            material.node_tree.nodes['Principled BSDF'].inputs[param[0]].default_value = param[1]
    else:
        print(f"Already have {name}")
        
if __name__ == "__main__":
    create_material("BlackSquare", [
        ('Base Color', (0, 0, 0, 1)),
        ('Roughness', 1.0),
    ])
    create_material("WhiteSquare", [
        ('Base Color', (1, 1, 1, 1)),
        ('Roughness', 0.7),
    ])

-- /code


-- categories
-- Blender 
-- Python 

-- metadata
-- date: 2022-10-16 22:42:58
-- id: 2gfbiuiy
-- status: published 
-- type: post
-- SCRUBBED_NEO: false
-- site: aws