Skip to content

Instantly share code, notes, and snippets.

View SuddenDevelopment's full-sized avatar
🤖

SuddenDevelopment SuddenDevelopment

🤖
View GitHub Profile
@SuddenDevelopment
SuddenDevelopment / update_panel_example.py
Created August 14, 2021 14:27
blender example of updating a panel with dynamic parameters / properties
import bpy
#define what the property in the colection will look like
class scad_params(bpy.types.PropertyGroup):
materialname: bpy.props.StringProperty(name="Material", default="")
slot: bpy.props.IntProperty(name="Slot")
#operator, connected the button that adds the params
class HiOp(bpy.types.Operator):
bl_idname = 'hi.go'
@SuddenDevelopment
SuddenDevelopment / blender_image_panel.py
Last active August 19, 2021 01:10
blender python example of showing an image in a panel
import bpy
import bpy.utils.previews
class HelloWorldPanel(bpy.types.Panel):
"""Creates a Panel in the Object properties window"""
bl_label = "HI"
bl_category = "HI"
bl_idname = "HI_Panel"
bl_space_type = 'VIEW_3D'
bl_region_type = 'UI'
@SuddenDevelopment
SuddenDevelopment / subPanel.py
Created September 11, 2021 03:09
Blender addon UI create collapsible subpanel
import bpy
class EXAMPLE_panel:
bl_space_type = "VIEW_3D"
bl_region_type = "UI"
bl_category = "Hi"
bl_options = {"DEFAULT_CLOSED"}
#The primary panel, no parents
class EXAMPLE_PT_panel_1(EXAMPLE_panel, bpy.types.Panel):
@SuddenDevelopment
SuddenDevelopment / blender_addon_template.py
Last active February 25, 2022 20:58
a cumulative template of common patterns to modify, comment and quickly use
### blender addon template
import bpy
#used for file open browser
from bpy_extras.io_utils import ImportHelper
####|| OPERATORS ||####
class HI_OT_DoStuff(bpy.types.Operator):
bl_idname = 'do.go'
bl_label = 'Do Stuff'
@SuddenDevelopment
SuddenDevelopment / properties.py
Created October 10, 2021 21:32
Blender addon property floatproperty example
### blender addon template
import bpy
#used for file open browser
from bpy_extras.io_utils import ImportHelper
####|| OPERATORS ||####
class HI_OT_DoStuff(bpy.types.Operator):
bl_idname = 'do.go'
bl_label = 'Do Stuff'
@SuddenDevelopment
SuddenDevelopment / from bpy discord.py
Created December 5, 2021 23:51
blender flatten verts to XY planr
import bpy
from mathutils import Matrix
import bmesh
ob = bpy.context.view_layer.objects.active
def create_empty(coord):
obj = bpy.data.objects.new('em', None)
bpy.context.collection.objects.link(obj)
obj.location = coord
@SuddenDevelopment
SuddenDevelopment / facePath.py
Created December 6, 2021 19:18
blender python, output 2d shape from selected faces on a mesh
import bpy, bmesh, mathutils
# an example script of getting the boundary paths of selected faces on a mesh and outputting them in x,y cooridnates.
# not sure what other people might do with it, but I found this a needed step in 2d-3d workflows
# fn determine if vert is a boundary OF SELECTION vert
def fnDetermineVertBoundary(objVert):
if objVert.select == True:
for objFace in objVert.link_faces:
@SuddenDevelopment
SuddenDevelopment / color_map.py
Created December 23, 2021 23:51
use a property group with a color picker to have a user defined color map in a panel
import bpy
#define what the property in the colection will look like
class color_map(bpy.types.PropertyGroup):
color: bpy.props.FloatVectorProperty(
name = "Color Picker",
subtype = "COLOR",
default = (1.0,1.0,1.0,1.0),
size = 4
)
@SuddenDevelopment
SuddenDevelopment / set_origins.py
Created December 24, 2021 20:42
function to set the origin of an object to it's min or max of an axis #Blender #origin
# move origin for all selected objects to edges of axis example usage, where xyz=012
# left = origin_to(obj,0,"-"), right = origin_to(obj,0,"+")
def origin_to(ob, axis="z", dir="-", matrix=Matrix()):
me = ob.data
mw = ob.matrix_world
local_verts = [matrix @ Vector(v[:]) for v in ob.bound_box]
o = sum(local_verts, Vector()) / 8
if dir == "-":
o[axis] = min(v[axis] for v in local_verts)
else:
@SuddenDevelopment
SuddenDevelopment / blender_addon_split_vertex_color.py
Last active January 27, 2022 03:35
Blender addon script to split all selected objects by material and map vertex colors per material by base color or user selection.
bl_info = {
"name": "Crayon",
"author": "Anthony Aragues",
"version": (0, 9),
"blender": (3,0,0),
"location": "n > Crayon",
"description": "vertex paint your objects by chosen colors quickly",
"warning": "",
"doc_url": "http://3dialogue.com/addons/crayon",
"category": "Import-Export",