Skip to content

Instantly share code, notes, and snippets.

View CGArtPython's full-sized avatar
👋

CGArtPython

👋
View GitHub Profile
@CGArtPython
CGArtPython / with_classes_example_1.py
Last active September 10, 2024 22:02
Beginner Blender Python Tutorial: Python Classes example 1 (used in tutorial: https://youtu.be/t2KEolkhIoA)
import bpy
class SquareFaceCube:
"""
a class to represent a cube mesh object with square faces
"""
def __init__(self):
# define the coordinates of each vertex
@CGArtPython
CGArtPython / example_class.py
Last active January 23, 2025 04:56
Beginner Blender Python Tutorial: Python Classes example class (used in tutorial: https://youtu.be/t2KEolkhIoA)
"""
Note: not using any blank lines to make it easier to copy into the Python interactive console
"""
class ExampleClass:
def __init__(self, example_parameter):
self.example_data = 33
self.example_param = example_parameter
print("message from constructor")
def example_method(self):
print(self.example_param)
@CGArtPython
CGArtPython / step_by_step_example_2.py
Last active October 31, 2022 06:00
Beginner Blender Python Tutorial: Python Classes; step by step version Example 2 (used in tutorial: https://youtu.be/t2KEolkhIoA)
import bpy
#######################################################################
# create a cube with square faces
#######################################################################
# define the coordinates of each vertex
verts = [
(-1.0, -1.0, -1.0),
(-1.0, 1.0, -1.0),
@CGArtPython
CGArtPython / with_functions_example_2.py
Last active October 31, 2022 06:01
Beginner Blender Python Tutorial: Python Classes; function version example 2 (used in tutorial: https://youtu.be/t2KEolkhIoA)
import bpy
def create_mesh_data(verts, edges, faces):
"""
create a mesh from the vert, edge, and face data
"""
mesh_data = bpy.data.meshes.new("cube_data")
mesh_data.from_pydata(verts, edges, faces)
@CGArtPython
CGArtPython / with_classes_example_2.py
Last active October 31, 2022 06:01
Beginner Blender Python Tutorial: Python Classes example 2 (used in tutorial: https://youtu.be/t2KEolkhIoA)
import bpy
class Cube:
"""
a class to represent a cube mesh object
"""
def __init__(self):
# define the coordinates of each vertex
@CGArtPython
CGArtPython / step_by_step_example_3.py
Last active October 31, 2022 06:00
Beginner Blender Python Tutorial: Python Classes; step by step version Example 3 (used in tutorial: https://youtu.be/t2KEolkhIoA)
import bpy
#######################################################################
# create a cube with square faces
#######################################################################
verts = [
(-1.0, -1.0, -1.0),
(-1.0, 1.0, -1.0),
(1.0, 1.0, -1.0),
@CGArtPython
CGArtPython / with_functions_example_2.py
Last active October 31, 2022 06:01
Beginner Blender Python Tutorial: Python Classes; function version example 3 (used in tutorial: https://youtu.be/t2KEolkhIoA)
import bpy
def create_mesh_data(name, verts, edges, faces):
"""
create a mesh from the vert, edge, and face data
"""
mesh_data = bpy.data.meshes.new(f"{name}_data")
mesh_data.from_pydata(verts, edges, faces)
@CGArtPython
CGArtPython / with_classes_example_3.py
Last active July 26, 2023 03:27
Beginner Blender Python Tutorial: Python Classes example 3 (used in tutorial: https://youtu.be/t2KEolkhIoA)
import bpy
class Shape:
"""
a class to represent a mesh object
"""
# example of a class variable
instance_count = 0
@CGArtPython
CGArtPython / from_a_for_loop_to_a_while_loop.py
Created November 28, 2022 07:31
Final code for a Beginner Blender Python Tutorial about using a for/while loop (link to tutorial: https://youtu.be/AcoYA4T2ErU)
# give Python access to Blender's functionality
import bpy
# extend Python's math functionality
import math
# add a cube mesh into the scene
bpy.ops.mesh.primitive_cube_add()
# get a reference to the currently active object
@CGArtPython
CGArtPython / refactor_and_animate.py
Created December 5, 2022 08:32
Final code for a Beginner Blender Python Tutorial about refactoring and animating (link to tutorial: https://youtu.be/tC_Bu-VO8p0)
# give Python access to Blender's functionality
import bpy
# extend Python's math functionality
import math
# extend Python functionality to generate random numbers
import random