Skip to content

Instantly share code, notes, and snippets.

@CGArtPython
Last active October 3, 2022 05:53
Show Gist options
  • Save CGArtPython/cb53598625fd6dd3f9d1b0f2b49aecb8 to your computer and use it in GitHub Desktop.
Save CGArtPython/cb53598625fd6dd3f9d1b0f2b49aecb8 to your computer and use it in GitHub Desktop.
Beginner Blender Python Tutorial: Python Lists Example 2 (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 cubes
cube_objects = []
# collect all cubes into a list
for obj in bpy.data.objects:
if "Cube" in obj.name:
cube_objects.append(obj)
# loop over the cubes and replace them with monkeys
for cube in cube_objects:
location = cube.location
bpy.ops.mesh.primitive_monkey_add(location=location)
bpy.data.objects.remove(cube)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment