Skip to content

Instantly share code, notes, and snippets.

View CGArtPython's full-sized avatar
👋

CGArtPython

👋
View GitHub Profile
@CGArtPython
CGArtPython / simple_cube_location_animation.py
Created June 1, 2023 03:19
Beginner Blender Python tutorial code for a cube location animation (link to video: https://www.youtube.com/watch?v=nmJqIaSZlRs&lc=Ugw4q26HfFYOa0zv1Wh4AaABAg)
# give Python access to Blender's functionality
import bpy
# add a cube into the scene
bpy.ops.mesh.primitive_cube_add()
# get a reference to the currently active object
cube = bpy.context.active_object
# insert keyframe at frame one
start_frame = 1
@CGArtPython
CGArtPython / blender_pie_menu_template_tut.py
Created May 30, 2023 08:29
Code for a YouTube tutorial "Exploring the Pie Menu Template in Blender with Python" (video link: https://youtu.be/zAMVFPr8ZIE)
'''
This code is based on a built-in Blender Python Tempalte - "UI Pie Menu"
'''
bl_info = {
"name": "Pie Menu: Template",
"description": "Pie menu example",
"author": "Viktor Stepanov",
"version": (0, 1, 1),
"blender": (2, 80, 0),
"location": "3D View",
@CGArtPython
CGArtPython / beveling_a_single_edge.py
Created April 22, 2023 16:43
Beginner Blender Python tutorial code for beveling a single edge
import bpy
import bmesh
bpy.ops.mesh.primitive_cube_add()
cube_obj = bpy.context.active_object
bpy.ops.object.editmode_toggle()
bpy.ops.mesh.select_all(action="DESELECT")
bm = bmesh.from_edit_mesh(cube_obj.data)
@CGArtPython
CGArtPython / get_script_folder_path.py
Created April 17, 2023 06:11
Beginner Blender Python tutorial code for retrieving the script file path when running from Blender's Text Editor, an Add-on, or the Command Line (tutorial video: https://youtu.be/jT2EbqMfKU8)
import bpy
import pathlib
# check if we are running from the Text Editor
if bpy.context.space_data != None and bpy.context.space_data.type == "TEXT_EDITOR":
# get the path to the SAVED TO DISK script when running from blender
print("bpy.context.space_data script_path")
script_path = bpy.context.space_data.text.filepath
else:
@CGArtPython
CGArtPython / setting_op_props_on_button.py
Created March 21, 2023 08:04
[Blender Python Add-on] Creating buttons using the same operator but with different parameters (extending script from this YouTube tutorial: https://youtu.be/0_QskeU8CPo)
"""
See YouTube tutorial here: https://youtu.be/0_QskeU8CPo
+
Adding 2 more buttons that set the operator's props
"""
bl_info = {
"name": "My Custom Panel",
@CGArtPython
CGArtPython / get_all_blend_files.py
Created March 21, 2023 07:14
[Blender Python Scripting] Get a list of blend file in the same folder as the Python script file
import pathlib
import pprint
path_to_current_dir = pathlib.Path(__file__).parent
###########
# Option 1
###########
blend_files = list()
@CGArtPython
CGArtPython / linking_objects_materials_scens_between_blend_files.py
Created March 12, 2023 08:57
Beginner Blender Python tutorial code for linking objects, materials, and scens from one .blend file into another (tutorial video: https://youtu.be/ZrN9w8SMFjo)
# extend Python's functionality to work with file paths
import pathlib
# give Python access to Blender's functionality
import bpy
def remove_libraries():
"""remove the linked blend files"""
bpy.data.batch_remove(bpy.data.libraries)
@CGArtPython
CGArtPython / simple_material_with_noise.py
Last active March 5, 2023 12:41
Beginner Blender Python tutorial code for creating a simple material and using a noise mask to control the roughness (tutorial video: https://youtu.be/D6Rm4WvVvoI)
# 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
@CGArtPython
CGArtPython / create_and_apply_a_simple_material.py
Created February 20, 2023 08:04
Beginner Blender Python tutorial code for creating a simple material and tweak its base color, metallic, and roughness (tutorial https://youtu.be/TdBYf8orLA4)
# give Python access to Blender's functionality
import bpy
# extend Python functionality to generate random numbers
import random
def partially_clean_the_scene():
# select all object in the scene
bpy.ops.object.select_all(action="SELECT")
@CGArtPython
CGArtPython / empty_following_a_bezier_circle_curve.py
Created January 31, 2023 06:26
Add a Bezier circle curve and an empty, make the empty animate by following the circle curve
import bpy
last_frame = 90
# set the lenght of the animation
bpy.context.scene.frame_end = last_frame
# add a Bezier circle curve into the scene
bpy.ops.curve.primitive_bezier_circle_add()
bezier_circle_obj = bpy.context.active_object