Skip to content

Instantly share code, notes, and snippets.

@bebeal
Created September 20, 2025 09:35
Show Gist options
  • Select an option

  • Save bebeal/a33065ab43aadcccc264230425a83e57 to your computer and use it in GitHub Desktop.

Select an option

Save bebeal/a33065ab43aadcccc264230425a83e57 to your computer and use it in GitHub Desktop.
template starting code for llms to generate python blender
import bpy
import math
import bmesh
# Always follow these rules
# - for every object you create, create it at the origin, size it, then move it if applicable
# - always center things (w.r.t the proper axis) when stacking/arranging them
# - everythign should be modular and easy to tweak
# - put parameters in constants at the top of the file but dont define a fuck ton of conflicting inter-dependant constants just the minimum ones which control the sizing
# Function to clean up mesh
def clean_mesh(obj):
bpy.context.view_layer.objects.active = obj
bpy.ops.object.mode_set(mode='EDIT')
bpy.ops.mesh.select_all(action='SELECT')
bpy.ops.mesh.remove_doubles() # Remove duplicate vertices
bpy.ops.mesh.normals_make_consistent() # Recalculate normals
bpy.ops.object.mode_set(mode='OBJECT')
# Function to apply bevel
def apply_bevel(obj, width=0.1, segments=5, clamp_overlap=False):
bevel_mod = obj.modifiers.new(name="Bevel", type='BEVEL')
bevel_mod.width = width
bevel_mod.segments = segments
bevel_mod.use_clamp_overlap = clamp_overlap
bpy.context.view_layer.objects.active = obj
bpy.ops.object.modifier_apply(modifier=bevel_mod.name)
# Clear scene
def clear_scene():
bpy.ops.object.select_all(action='SELECT')
bpy.ops.object.delete()
def create_boolean_modifier(obj, target, operation='DIFFERENCE', use_self=True, use_hole_tolerant=True, solver='EXACT', name="bool_mod"):
bool_mod = obj.modifiers.new(name=name, type='BOOLEAN')
bool_mod.solver = solver
bool_mod.operation = operation
bool_mod.object = target
bool_mod.use_self = use_self
bool_mod.use_hole_tolerant = use_hole_tolerant
bpy.context.view_layer.objects.active = obj
bpy.ops.object.modifier_apply(modifier=bool_mod.name)
return bool_mod
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment