Skip to content

Instantly share code, notes, and snippets.

@Andrej730
Andrej730 / encoder.py
Last active April 9, 2024 23:02
Custom Python json.JSONEncoder that doesn't create add new lines for list items
"""Implementation of JSONEncoder
"""
import re
import collections.abc
try:
from _json import encode_basestring_ascii as c_encode_basestring_ascii
except ImportError:
c_encode_basestring_ascii = None
try:
@Andrej730
Andrej730 / text_editor_reload_if_modified.py
Last active October 13, 2023 09:50
Blender - Automatically reload texts which has changed externally
# ***** BEGIN GPL LICENSE BLOCK *****
#
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
@Andrej730
Andrej730 / reroute_to_python_console.py
Created October 5, 2023 11:36 — forked from tin2tin/log.py
Route system output (stdout/stderr) of Blender to the app console (install as an addon)
bl_info = {
"name": "Reroute System Console Ouput to Python Console",
"author": "@tamask, @tin2tin, @Andrej730",
"version": (1, 0),
"blender": (3, 0, 0),
"location": "Python Console header",
"description": "",
"warning": "",
"category": "Development"
}
@Andrej730
Andrej730 / transfer_vertex_order.py
Created September 16, 2023 17:13
transfer_vertex_order.py
# ##### BEGIN GPL LICENSE BLOCK #####
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
@Andrej730
Andrej730 / notes_solvespace_example_py.md
Last active September 7, 2023 09:18
Solvespace Python example and notes
@Andrej730
Andrej730 / generate_bolts_yml.py
Created July 17, 2023 11:52
generate_bolts_yml.py
from pathlib import Path
from pprint import pprint
def find_nth_overlapping(haystack, needle, n=1):
start = haystack.find(needle)
while start >= 0 and n > 1:
start = haystack.find(needle, start+1)
n -= 1
return start
@Andrej730
Andrej730 / python_console_scripts.py
Last active July 14, 2023 08:50
Run scripts in Python Console Blender addon
# got it from
# https://blender.stackexchange.com/questions/5394/is-there-anyway-to-make-blender-print-errors-in-the-ui
import bpy
bl_info = {
"name": "Run scripts in Python Console",
"author": "CoDEmanX",
"version": (1, 0),
"blender": (2, 80, 0),
@Andrej730
Andrej730 / random_object_colors.py
Created June 4, 2023 19:24
random_object_colors operator for blender
bl_info = {
"name": "Random Object Colors",
"author": "@Andrej730",
"version": (1, 0),
"blender": (2, 90, 0),
"location": "F3 -> Random Object Color",
"description": "",
"warning": "",
"category": "Objects"
}
# minimal shader example to create smoothed polylines on Metal
import bpy
import gpu
from gpu_extras.batch import batch_for_shader
polyline_vert_glsl = """
// emits 6 vertex per each line
// see: https://projects.blender.org/blender/blender/issues/107332