Skip to content

Instantly share code, notes, and snippets.

View gtalarico's full-sized avatar
♥️
Python, Javascript, and Go

Gui Talarico gtalarico

♥️
Python, Javascript, and Go
View GitHub Profile
@gtalarico
gtalarico / revitapidocs_CreateTextFunc.py
Last active September 1, 2016 01:04
RevitAPI::Code Snippets::Create Text Function
''' Create a text annotation element.
Does not include start/commit transaction.'''
def create_text(view, text, point, align):
"""Creates a Revit Text.
create_test(view, text_string, point)
view: view object to insert text
text: text to be inserted
point: insertion point - XYZ() instance
align: 'left', 'right', or 'center'
@gtalarico
gtalarico / revitapidocs_GetPhaseByName.py
Last active September 1, 2016 01:01
RevitAPI::Code Snippets::Get Phase By Name
from Autodesk.Revit.DB import Phase, FilteredElementCollector
def get_phase_by_name(phase_name):
phase_collector = FilteredElementCollector(doc).OfClass(Phase)
for phase in phase_collector:
if phase.Name.Equals(phase_name):
return phase
phase = get_phase_by_name('01 - Existing')
print phase.Name
@gtalarico
gtalarico / revitapidocs_GetFilledRegionByName.py
Last active September 1, 2016 01:01
RevitAPI::Code Snippets::Get Filled Region Id - by Name
from Autodesk.Revit.DB import Element, FilteredElementCollector
from Autodesk.Revit.DB import FilledRegionType, FilledRegion
def fregion_id_by_name(name=None):
"""Get Id of Filled Region Type by Name.
Loops through all types, tries to match name.
If name not supplied, first type is used.
If name supplied does not match any existing types, last type is used
"""
@gtalarico
gtalarico / revitapidocs_CropImage.py
Last active September 1, 2016 01:00
RevitAPI::Working Tools::Crop Selected Image Using a Filled Region
"""
Crop Image
Crops an Image to a Filled Region Boundary
TESTED REVIT API: 2015
Copyright (c) 2014-2016 Gui Talarico
github.com/gtalarico
This script is part of PyRevitPlus: Extensions for PyRevit
github.com/gtalarico/pyrevitplus
@gtalarico
gtalarico / revitapidocs_MakeFloorFromRooms.py
Created September 4, 2016 19:48
RevitAPI::Working Tools::Make Floors From Rooms
"""
Make Floors
Create Floors from Selected Rooms
TESTED REVIT API: 2015
Gui Talarico
github.com/gtalarico
"""
import sys
@gtalarico
gtalarico / revitapidocs_GetSelectedElements.py
Last active June 14, 2023 08:10
RevitAPI::Code Snippets::Get Selected Elements
uidoc = __revit__.ActiveUIDocument
def get_selected_elements():
"""Return Selected Elements as a list[]. Returns empty list if no elements are selected.
Usage:
- Select 1 or more elements
> selected_elements = get_selected_elements()
> [<Autodesk.Revit.DB.FamilyInstance object at 0x0000000000000034 [Autodesk.Revit.DB.FamilyInstance]>]
"""
selection = uidoc.Selection
@gtalarico
gtalarico / revitapidocs_ImportImage.py
Created September 6, 2016 19:16
RevitAPI::Code Snippets::Import Image
# Import Image
# http://www.revitapidocs.com/2015/05c3dbe2-fe7e-c293-761d-b11f356a011b.htm
from clr import StrongBox
from Autodesk.Revit.DB import XYZ, ImageImportOptions, BoxPlacement, BuiltInParameter
# Import Options
import_options = ImageImportOptions()
import_options.Placement = BoxPlacement.Center
import_options.RefPoint = XYZ(0,0,0)
@gtalarico
gtalarico / zip_and_hash.py
Created September 10, 2016 23:01
Zip a directory and get hash (useful for checking if contents have changed)
# http://stackoverflow.com/questions/1855095/how-to-create-a-zip-archive-of-a-directory
import os
import zipfile
import hashlib
import time
def zipdir(path, ziph):
for root, dirs, files in os.walk(path):
if '.git' not in root:
for file in files:
@gtalarico
gtalarico / revitapidocs_CycleTypes.py
Last active September 19, 2016 04:57
RevitAPIDOCS::Code Snippets::Cycles through Family Types in Family Manager
"""
CycleType
Cycle through available types in family manager
TESTED REVIT API: 2015
github.com/gtalarico
"""
__doc__ = 'Cycles through available types in family manager. \n' \
'Must be in Family Document.'
@gtalarico
gtalarico / logger.py
Last active September 26, 2016 05:08
Logger Wrapper
import logging
import sys
class LoggerWrapper():
""" Logger Wrapper to extend loggers functionality.
Usage:
logger = LoggerWrapper()
Additional Features:
logger.title('Message'): Outputs lines above and below, uses clean format
logger.error('Message'): appends errmsg to self.errors.