Skip to content

Instantly share code, notes, and snippets.

View SuddenDevelopment's full-sized avatar
🤖

SuddenDevelopment SuddenDevelopment

🤖
View GitHub Profile
@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 / 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 / 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 / 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 / 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_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 / 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 / importOps.py
Last active June 10, 2021 02:56
List of operations to cleanup imported objects Chipp Walters gave me, in script form to save time.
# List of common operations to run on imported objects like .stl
# paste all or some into a script window in blender and run.
# If there's any interest in seeing this in addon form somewhere let me know, it seemed too basic/common to be another addon to install.
import bpy
# resize objects imported that were unit=1mm and Blender is set at 1m
bpy.ops.transform.resize(value=(0.001, 0.001, 0.001), orient_type='GLOBAL', orient_matrix=((1, 0, 0), (0, 1, 0), (0, 0, 1)), orient_matrix_type='GLOBAL', mirror=True, use_proportional_edit=False, proportional_edit_falloff='SMOOTH', proportional_size=1, use_proportional_connected=False, use_proportional_projected=False)
# toggle to edit mode for a few things
bpy.ops.object.editmode_toggle()
@SuddenDevelopment
SuddenDevelopment / react component template.jsx
Last active March 21, 2021 20:34
organized template for creating react components
/*----====|| LIBRARY IMPORTS || ====----*/
//import React, { useContext,useEffect,useState } from 'react';
//import { Layout } from 'antd';
/*----====|| COPMPONENT IMPORTS || ====----*/
//import MyComponent from './components/myComponent.js';
/*----====|| CONTEXT || ====----*/
import {UserContext,ConfigContext} from '../context.js';
/*----====|| STYLE IMPORTS || ====----*/
@SuddenDevelopment
SuddenDevelopment / blender_fnGetScale.py
Last active October 13, 2021 18:56
blender get the size in x,y,z for an array of vectors
#example calling
# arrVerts=[]
# for objVert in objMesh.verts:
# if objVert.select == True:
# arrVerts.append(objVert)
objScale= fnGetScale(arrVerts)
print(objScale)
def fnGetScale(arrVerts):