Skip to content

Instantly share code, notes, and snippets.

@nodatasheet
nodatasheet / errors_swallowing_decorator.py
Last active January 6, 2024 09:36
Example of decorator that swallows errors
from functools import wraps
def errors_swallower(errors_to_swallow=None):
"""Swallows provided types of errors. Or all, if nothing provided."""
if errors_to_swallow is None:
errors_to_swallow = BaseException,
def decorator(func):
@wraps(func)
@nodatasheet
nodatasheet / ꟿ FamilyInstance.ByGeometry.py
Created June 16, 2022 15:24
Clockwork's node to work in all current revit versions
#Copyright(c) 2016, Dimitar Venkov
# @5devene, dimitar.ven@gmail.com
import clr
import System
from System.Collections.Generic import *
from itertools import repeat
pf_path = System.Environment.GetFolderPath(System.Environment.SpecialFolder.ProgramFilesX86)
def is_p1_smaller_p2(p1, p2):
# type: (Point, Point) -> bool
"""Is p1 < p2?
use first method from here:
https://math.stackexchange.com/a/54657
x1 < x2
or
x1 = x2 and y1 < y2
or
x1 = x2 and y1 = y2 and z1 < z2
@nodatasheet
nodatasheet / testing_merge_bboxes.py
Last active May 28, 2022 00:19
torturing bounding boxes
import timeit
mysetup = """
import clr
from random import randint
clr.AddReference("RevitNodes")
import Revit
clr.ImportExtensions(Revit.Elements)
clr.ImportExtensions(Revit.GeometryConversion)
# Based on SelectLinkedFace and SelectFaces+ from Springs
# Copyright(c) 2017, Dimitar Venkov
# @5devene, dimitar.ven@gmail.com
# www.badmonkeys.net
import clr
clr.AddReference("RevitAPIUI")
from Autodesk.Revit.UI import *