Created
April 28, 2022 02:03
-
-
Save GGLinnk/6d148900bddc53f8aab7a9d760bcc53c to your computer and use it in GitHub Desktop.
Blender Python API: Gets materials by creating them or getting them by name.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import bpy | |
def get_material(material_name: str) -> bpy.types.Material: | |
return bpy.data.materials.get(material_name) or bpy.data.materials.new(name=material_name) | |
def get_materials(material_names: list) -> list: | |
return [get_material(mat_name) for mat_name in material_names] | |
if __name__ == __main__: | |
get_material("TEST_MAT") | |
get_materials(["TEST_MAT", "MAT1", "MAT2"]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment