Last active
December 1, 2022 07:23
-
-
Save CGArtPython/26937bf3f09faa6288426e2b298fde99 to your computer and use it in GitHub Desktop.
Beginner Blender Python Tutorial: Python Dictionaries Example 2 scene setup code (used in tutorial: https://youtu.be/FkJ2XanNBR4)
This file contains hidden or 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
| # give Python access to Blender's functionality | |
| import bpy | |
| # extend Python functionality to generate random numbers | |
| import random | |
| # add ico spheres into the scene | |
| object_count = 10 | |
| for _ in range(object_count): | |
| x = random.uniform(-5, 5) | |
| y = random.uniform(-5, 5) | |
| z = random.uniform(-5, 5) | |
| bpy.ops.mesh.primitive_ico_sphere_add(radius=1, location=(x, y, z)) | |
| # add cubes into the scene | |
| for _ in range(object_count): | |
| x = random.uniform(-5, 5) | |
| y = random.uniform(-5, 5) | |
| z = random.uniform(-5, 5) | |
| bpy.ops.mesh.primitive_cube_add(location=(x, y, z)) | |
| # add cones into the scene | |
| for _ in range(object_count): | |
| x = random.uniform(-5, 5) | |
| y = random.uniform(-5, 5) | |
| z = random.uniform(-5, 5) | |
| bpy.ops.mesh.primitive_cone_add(location=(x, y, z)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment