Skip to content

Instantly share code, notes, and snippets.

View SuddenDevelopment's full-sized avatar
🤖

SuddenDevelopment SuddenDevelopment

🤖
View GitHub Profile
@SuddenDevelopment
SuddenDevelopment / batchProcessImages.py
Created February 21, 2023 05:32
add a grayscale gaussian blur to an image and set the blacks to transparent, converting from jpg to png
import numpy as np
import cv2
import os
# install all the above packages with pip3
# run this by setting the directories and calling fro command line
# python3 processImages.py
IMAGEFOLDER = '/Users/anthonyaragues/Downloads/in/'
OUTPUTFOLDER = '/Users/anthonyaragues/Downloads/out/'
@SuddenDevelopment
SuddenDevelopment / blender_gltf_instances_prep.py
Created January 23, 2023 15:45
Blender bulk apply scale, location and separate by loose parts
import bpy
for obj in bpy.context.scene.objects:
if obj.type == 'MESH':
obj.select_set(True)
try:
bpy.context.view_layer.objects.active = obj
bpy.ops.mesh.separate(type='LOOSE')
bpy.ops.object.transform_apply(location=False, rotation=True, scale=True)
except:
@SuddenDevelopment
SuddenDevelopment / blender_bulk_uv_project.py
Created January 23, 2023 15:36
bulk smart unwrap a set of selected objects in Blender
import bpy
arrObjects = bpy.context.selected_objects
for obj in arrObjects:
obj.select_set(False)
for obj in arrObjects:
obj.select_set(True)
@SuddenDevelopment
SuddenDevelopment / blender_mixrgb_fix_3.3.py
Created January 22, 2023 01:37
backport blender 3.4 mix shader node to 3.3 mix rgb node
import bpy
def changeNodes(objNodeTree):
for objNode in objNodeTree.nodes:
if objNode.type == 'GROUP' and objNode.node_tree:
changeNodes(objNode.node_tree)
# look for the generic mix node from 3.4 to try and make it mixrgb in 3.3
# [0]Factor, [2]A, [4]B == [0]fac, [1]color1, [2]color2
elif objNode.type=='' and objNode.inputs[0].name == 'Factor':
@SuddenDevelopment
SuddenDevelopment / blender_split.py
Created January 15, 2023 20:30
Blender Python Script to Split all objects in a scene
import bpy
for obj in bpy.context.scene.objects:
obj.select_set(True)
# split the mesh
if obj.type == 'MESH':
bpy.ops.mesh.separate(type='LOOSE')
obj.select_set(False)
@SuddenDevelopment
SuddenDevelopment / version.py
Last active January 3, 2023 22:14
blender addon version check and message update
# 1. include this version file
# 2. put a json file online format = { "version": "1.4.0", "message": "upgrade for these new features" }
# 3. point to the url in version.py
# 4. register a prop to show the ui message bpy.types.WindowManager.flex_update = bpy.props.StringProperty(name="Info", default="")
# 5. point to that property name in version.py
# 6. setup the UI to ue that property if populated
#if bpy.context.window_manager.flex_update != "":
# box = layout.box()
# row = box.row(align=True)
# row.alignment = 'EXPAND'
@SuddenDevelopment
SuddenDevelopment / poc_2d_gizmos.py
Created December 23, 2022 12:39
blender python ui gizmo POC, does NOT work with custom icons
from bpy.types import (
GizmoGroup
)
import bpy
bl_info = {
"name": "POC buttons",
"description": "POC 2D BUTTON script refactored from GP Animator Desk addon",
"author": "Anthony Aragues, P.Świda",
"version": (0, 0, 1),
@SuddenDevelopment
SuddenDevelopment / gizmo_button.py
Created December 21, 2022 12:35
Display a 2d button gizmo in the 3dview window for an addon UI
from bpy.types import (
GizmoGroup
)
import bpy
bl_info = {
"name": "POC buttons",
"description": "POC 2D BUTTON script refactored from GP Animator Desk addon",
"author": "Anthony Aragues, P.Świda",
"version": (0, 0, 1),
"blender": (3, 4, 0),
@SuddenDevelopment
SuddenDevelopment / duplicateVerts.py
Created October 13, 2022 20:43
Blender Python to select all duplicates of selected object from vertex count and position
import bpy
objTarget = bpy.context.active_object
for obj in bpy.data.objects:
isSame = True
if obj.type != objTarget.type:
isSame = False
if len(obj.data.vertices) == len(objTarget.data.vertices) and isSame == True:
for i,vert in enumerate(obj.data.vertices):
@SuddenDevelopment
SuddenDevelopment / duplicateMesh.py
Created October 13, 2022 20:24
Blender Python to find duplicate objects based on mesh name
import bpy
objTarget = bpy.context.active_object
for obj in bpy.data.objects:
if obj.data.name[:-4] == objTarget.data.name:
obj.select_set(True)