Skip to content

Instantly share code, notes, and snippets.

@MrMagicPenguin
MrMagicPenguin / elements_in_rooms.py
Last active May 12, 2024 22:16
Finds elements based on their Revit Room. This implementation does not rely on the IsPointInRoom() method of the Room Class, so in theory this could be expanded to query against any provided BoundingBoxXYZ.
# Load the Python Standard and DesignScript Libraries
import sys
import clr
clr.AddReference('ProtoGeometry')
from Autodesk.DesignScript.Geometry import *
# import doc manager
# Use this to access the hidden RVT DB
clr.AddReference("RevitServices")
import RevitServices
# this is a class
class Crop:
#This is how you define an instance of a class.
# __init__ is the 'constructor' or the function that is used when you generate a new instance of the class.
# notice that one of the arguments in the constructor is self.
# When you refer to 'self', you are referring to a property or function stored in the instanced class.
# 'self' is always passed as an argument when defining a function within a class - it needs to know its talking about itself!
def __init__(self, cropType):
# As part of creating an instance of the Crop class, we want to assign a cropType to it.
# we are taking the argument passed in the Constructor, and assigning it to a variable called cropType.
@MrMagicPenguin
MrMagicPenguin / BatchRename.py
Created June 28, 2022 20:50
UI Tool to batch rename objects within a Collection. Features field disabling, list filtered by Type
import bpy
from bpy.types import (PropertyGroup)
from bpy.props import (StringProperty, PointerProperty, CollectionProperty, BoolProperty)
C = bpy.context
D = bpy.data
class odalysProperties(PropertyGroup):
target_collection: PointerProperty(
@MrMagicPenguin
MrMagicPenguin / collection2empty.py
Last active June 28, 2022 11:13
Convert a hierarchy of Blender Collections to a hierarchy of Empties. Useful for formatting .FBX or other file formats on export to reflect in-house hierarchy & organization.
# Credit to Christopher Baumeister on BlenderArtists for the base script.
# I have added logic for nested collections.
# Original topic: https://blenderartists.org/t/blender-2-8-export-fbx-while-keeping-collections-hierarchy/1142655/5
import bpy
sCollection = bpy.context.collection
def parentCol(_colParent, _objParent):
for col in _colParent.children:
@MrMagicPenguin
MrMagicPenguin / DedupMaterials.js
Created October 25, 2021 23:56
Remove duplicate materials from objects
import {Document} from "@gltf-transform/core";
export default function DedupMaterials(document) {
const root = document.getRoot()
const root_mats = root.listMaterials()
root_mats.forEach((mat) =>{
if (mat.getName() === root_mats[0].getName() && mat !== root_mats[0]){
mat.detach()
mat.dispose()
}
// Pan
if (Input.GetMouseButton(1)) // right click
{
// Clamp bounds of *rig*
positionZ = Input.GetAxis("Mouse X") * moveSpeed;
positionY = -Input.GetAxis("Mouse Y") * moveSpeed;
// clamp position
newPosition.z += positionZ;
newPosition.y += positionY;
@MrMagicPenguin
MrMagicPenguin / ClampPosition.cs
Created August 25, 2021 19:56
Clamp position within axis aligned bounding box
static Vector3 ClampPosition(Vector3 pos, Bounds bounds)
{
// if pos.x > bounds.max.x
// pos.x = bounds.min
// if pos.x < bounds.min.x
// pos.x = bounds.min.x
// if pos.y > bounds.max.y
// pos.y = bounds.max.y
// if pos.y < bounds.min.y
// pos.y = bounds.min.y
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class CameraRigController : MonoBehaviour
{
public float moveSpeed;
public float moveTime;
public float rotationAmount;
@MrMagicPenguin
MrMagicPenguin / cube_action.py
Created August 4, 2021 18:04
Duplicate object in instance, give it random action
import bpy
from random import uniform
def random_scale_action():
action = bpy.data.actions.new("RandomScaleAction")
data_path = "scale"
# (frame, value) for keyframe point
for axis in [0, 1, 2]:
# new fcurve
fc = action.fcurves.new(data_path, index=axis)