Skip to content

Instantly share code, notes, and snippets.

@CGArtPython
Last active October 3, 2022 05:54
Show Gist options
  • Save CGArtPython/025393b66ae12a18021eebdcfd600754 to your computer and use it in GitHub Desktop.
Save CGArtPython/025393b66ae12a18021eebdcfd600754 to your computer and use it in GitHub Desktop.
Beginner Blender Python Tutorial: Python Lists Example 3 (used in tutorial: https://youtu.be/-Gc3UHGoxgc)
# give Python access to Blender's functionality
import bpy
# extend Python functionality to generate random numbers
import random
# create a list of colors
colors = [
[0.888, 0.515, 0.016, 1.0],
[0.03, 0.376, 0.521, 1.0],
[0.694, 0.019, 0.019, 1.0],
[0.888, 0.03, 0.03, 1.0],
[1.0, 0.22, 0.631, 1.0],
[0.016, 0.491, 0.497, 1.0],
[0.001, 0.694, 0.041, 1.0],
]
# add a plane
bpy.ops.mesh.primitive_plane_add()
plane_object = bpy.context.active_object
# create a new material
material = bpy.data.materials.new(name=f"random_diffuse_material")
material.diffuse_color = random.choice(colors)
# add material to object
plane_object.data.materials.append(material)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment