Last active
December 1, 2022 07:37
-
-
Save CGArtPython/7cd5e2ad0b9ccba65fbeba2c790c0d29 to your computer and use it in GitHub Desktop.
Beginner Blender Python Tutorial: Python Dictionaries Example 2 (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 | |
| cube_key = "cubes" | |
| ico_key = "spheres" | |
| cone_key = "cones" | |
| # create a dict of mesh lists | |
| mesh_objects = { | |
| cube_key: list(), | |
| ico_key: list(), | |
| cone_key: list(), | |
| } | |
| # collect all meshs into the dict | |
| for obj in bpy.data.objects: | |
| if "Cube" in obj.name: | |
| mesh_objects[cube_key].append(obj) | |
| continue | |
| if "Ico" in obj.name: | |
| mesh_objects[ico_key].append(obj) | |
| continue | |
| if "Cone" in obj.name: | |
| mesh_objects[cone_key].append(obj) | |
| # create a dict of locations | |
| mesh_z_locations = { | |
| cube_key: 0, | |
| ico_key: -5, | |
| cone_key: 5, | |
| } | |
| # loop over the meshes | |
| for key, value in mesh_objects.items(): | |
| for mesh_obj in value: | |
| mesh_obj.location.z = mesh_z_locations[key] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment