Skip to content

Instantly share code, notes, and snippets.

View CGArtPython's full-sized avatar
👋

CGArtPython

👋
View GitHub Profile
@CGArtPython
CGArtPython / ico_sphere_random_color_faces_part_1.py
Last active November 27, 2023 10:45
A Blender Python script to generate an ico sphere with random colors applied to each face. Part 1 of a video tutorial https://www.youtube.com/watch?v=VpPwAsI12CQ
# give Python access to Blender's functionality
import bpy
# give Python access to Blender's mesh editing functionality
import bmesh
# extend Python functionality to generate random numbers
import random
# add an ico sphere
@CGArtPython
CGArtPython / ico_sphere_random_color_faces_part_2.py
Last active August 8, 2022 05:18
A Blender Python script to generate an ico sphere with random colors applied to each face. Part 2 of a video tutorial https://www.youtube.com/watch?v=WnZX--idSQI
# give Python access to Blender's functionality
import bpy
# give Python access to Blender's mesh editing functionality
import bmesh
# extend Python functionality to generate random numbers
import random
@CGArtPython
CGArtPython / draw_text_on_the_verts_of_a_mesh.py
Created August 26, 2022 16:23
A Blender Python script that draws text next to the verts of a active mesh
import bpy
import blf
from bpy_extras.view3d_utils import location_3d_to_region_2d
def draw_text_on_verts():
font_id = 0
region = bpy.context.region
rv3d = bpy.context.space_data.region_3d
@CGArtPython
CGArtPython / phyllotaxis.py
Created September 5, 2022 07:05
Beginner Blender Python Tutorial: Phyllotaxis; Video tutorial: https://www.youtube.com/watch?v=WHAQwhr1Jto
"""
Creating a phyllotaxis pattern based on formula 4.1 from
http://algorithmicbotany.org/papers/abop/abop-ch4.pdf
"""
# give Python access to Blender's functionality
import bpy
# extend Python functionality to generate random numbers
import random
@CGArtPython
CGArtPython / copy_location_animation.py
Created September 18, 2022 06:41
Blender Python script that copies the location animation on the Z axis from one cube to another.
"""
Copy location animation on the Z axis from one cube to another.
This script expects that there are two cubes in the scene.
The first one named 'Cube' that has an location animation on the Z axis.
The second one named 'Cube.001'. We will be copying the animation from 'Cube' to 'Cube.001'.
"""
# give Python access to Blender's functionality
import bpy
@CGArtPython
CGArtPython / start_scene_collection_exercises.py
Last active September 19, 2022 06:11
The starting code for a exercise video about using Python for working with Blender collections. (Link to video: https://www.youtube.com/watch?v=rWt-SY0NAHs )
# give Python access to Blender's functionality
import bpy
# create a variable to set the spacing between object origins
location_offset = 3
# create a row of cubes along the X-axis
for i in range(10):
bpy.ops.mesh.primitive_cube_add(location=(i * location_offset, 0, 0))
@CGArtPython
CGArtPython / finished_scene_collection_exercises.py
Last active September 19, 2022 06:12
The finished code for a exercise video about using Python for working with Blender collections. (Link to video: https://www.youtube.com/watch?v=rWt-SY0NAHs )
# give Python access to Blender's functionality
import bpy
# Note: make sure to run this script start_scene_collection_exercises.py https://gist.github.com/CGArtPython/8adc0c15813684db465a359313060164
# before executing the rest of this script
col_name = "monkeys"
collection = bpy.data.collections.new(name=col_name)
# if you didn't create a variable
@CGArtPython
CGArtPython / circles_in_a_circle.py
Last active October 2, 2022 01:15
Version of script for a tutorial using a circle mesh instead of a ico sphere https://www.youtube.com/watch?v=uOQ-CPcaqMo&lc=UgzQQKuVzGyx6Ke4DvJ4AaABAg
"""
https://stackoverflow.com/a/42879185
https://en.wikipedia.org/wiki/Parametric_equation#Circle
https://sinestesia.co/blog/tutorials/python-tubes-cilinders/
https://blog.wolfram.com/2015/06/28/2-pi-or-not-2-pi/
Great explanation of the math behind this
@CGArtPython
CGArtPython / example_1a.py
Last active October 3, 2022 05:52
Beginner Blender Python Tutorial: Python Lists Example 1A (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 coordinates
coordinates = []
coordinate_count = 10
@CGArtPython
CGArtPython / example_1b.py
Last active October 3, 2022 05:53
Beginner Blender Python Tutorial: Python Lists Example 1B (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 coordinates
coordinates = []
coordinate_count = 10