Skip to content

Instantly share code, notes, and snippets.

View CGArtPython's full-sized avatar
👋

CGArtPython

👋
View GitHub Profile
@CGArtPython
CGArtPython / initial_code_rig_ui_panel.py
Created July 12, 2024 08:26
Initial code for a Blender Python tutorial about creating a simple Rig UI panel. (video link https://www.youtube.com/watch?v=quXn5VoVyAI&lc=UgxGgnYLDtaIVAFxA754AaABAg )
# give Python access to Blender's functionality
import bpy
class VIEW3D_PT_my_rig_ui(bpy.types.Panel):
bl_space_type = 'VIEW_3D'
bl_region_type = 'UI'
bl_category = 'Item'
bl_label = "My Rig UI"
bl_idname = "VIEW3D_PT_rig_ui"
@CGArtPython
CGArtPython / allign_shader_nodes.py
Created June 19, 2024 08:29
This script demonstrates how to align nodes in the Shader Editor using the built-in 'node_arrange' add-on in Blender.
"""
This script demonstrates how to align nodes in the Shader Editor using the built-in 'node_arrange' add-on in Blender.
Note: This is not the most optimal method as it relies on a bpy.ops call, but it is functional.
The script performs the following steps:
1. Checks if the 'node_arrange' add-on is enabled and enables it if it is not.
2. Defines a context manager to switch the area type to the Shader Editor.
3. Aligns the nodes of a specified material using the 'node_arrange' add-on.
@CGArtPython
CGArtPython / File Logging Addon example.py
Created May 9, 2024 07:55
A example of an addon that logs into a file
bl_info = {
"name": "File Logging Addon",
"description": "Creates a panel with three buttons that add a cube, cone, and sphere to the scene. Logs messages to a file.",
"author": "Viktor Stepanov",
"version": (0, 0, 1),
"blender": (4, 0, 0),
"location": "View3D",
"warning": "This addon is still in development.",
"wiki_url": "",
"category": "Object"
@CGArtPython
CGArtPython / final_context_advanced.py
Created May 3, 2024 07:15
Example of how context managers work for mesh editing in Blender
import contextlib
import bpy
import bmesh
class Mode:
Edit = "EDIT_MESH"
Object = "OBJECT"
@CGArtPython
CGArtPython / blender_driver_functions_persistent_library.py
Created November 21, 2023 21:32
An add-on example for creating a persistent library of Python-powered Blender driver functions (find out more about Blender Python drivers here https://www.youtube.com/watch?v=yiMGxlRv8h4&lc=UgwlEGLUyWsiKhPPlml4AaABAg )
# name this file __init__.py
import bpy
ADDON_NAME = "My Diver Library"
bl_info = {
"name": "My Diver Library",
"author": "Viktor Stepanov",
"version": (0, 0, 1),
@CGArtPython
CGArtPython / get_selected_verts_via_list_comprehension.py
Created September 11, 2023 07:13
Blender Python get selected verts via list comprehension (video tutorial here: https://youtu.be/N3U2noAHgBo)
import bpy
import bmesh
# get a reference to the active object
mesh_obj = bpy.context.active_object
# create a new bmesh
bm = bmesh.from_edit_mesh(mesh_obj.data)
selected_verts = [vert for vert in bm.verts if vert.select]
@CGArtPython
CGArtPython / bmesh_icosphere.py
Created September 11, 2023 07:10
Creating an icosphere using the Bmesh Blender Python module. (video tutorial here: https://youtu.be/N3U2noAHgBo)
import bpy
import bmesh
obj_name = "my_shape"
# create the mesh data
mesh_data = bpy.data.meshes.new(f"{obj_name}_data")
# create the mesh object using the mesh data
mesh_obj = bpy.data.objects.new(obj_name, mesh_data)
@CGArtPython
CGArtPython / create_shape_from_scratch_with_bmesh.py
Created September 11, 2023 07:09
Creating a pyramid from scratch using the Bmesh Blender Python module. (video tutorial here: https://youtu.be/N3U2noAHgBo)
import bpy
import bmesh
obj_name = "my_shape"
# create the mesh data
mesh_data = bpy.data.meshes.new(f"{obj_name}_data")
# create the mesh object using the mesh data
mesh_obj = bpy.data.objects.new(obj_name, mesh_data)
@CGArtPython
CGArtPython / use_custom_displacement_image_texture_in_displacement_modifier.py
Created September 8, 2023 07:15
Use a custom displacement image texture in a displacement modifier
# downlaod and extract example image from there https://polyhaven.com/a/mud_cracked_dry_03
import bpy
# set path to the folder where the texture is
image_folder_path = r'c:\path\to\your\textures'
# set the name of the displacement texture image
image_name = 'name_of_your_texture.png'
# load the image
@CGArtPython
CGArtPython / bmesh_bevel_from_object_mode_mesh.py
Created August 28, 2023 07:16
Blender Python script that bevels the edges of an active object that is in OBJECT mode (see tutorial here: https://youtu.be/TFQMNcTj5Jw)
import bpy
import bmesh
# get a reference to the active object
mesh_obj = bpy.context.active_object
# create a new bmesh
bm = bmesh.new()
# initialize the bmesh data using the mesh data