def load_session(): """Handles loading/reloading of the pyRevit addin and extensions. To create a proper ui, pyRevit extensions needs to be properly parsed and a dll assembly needs to be created. This function handles these tasks through interactions with .extensions, .loader.asmmaker, and .loader.uimaker Example: >>> from pyrevit.loader.sessionmgr import load_session >>> load_session() # start loading a new pyRevit session Returns: None """ # initialize timer to measure load time timer = Timer() # perform pre-load tasks _perform_onsessionload_ops() # create a new session _new_session() # perform post-load tasks _perform_onsessionloadcomplete_ops() # log load time and thumbs-up :) endtime = timer.get_time() success_emoji = ':ok_hand_sign:' if endtime < 3.00 else ':thumbs_up:' logger.info('Load time: {} seconds {}'.format(endtime, success_emoji))
def load_session(): """Handles loading/reloading of the pyRevit addin and extensions. To create a proper ui, pyRevit extensions needs to be properly parsed and a dll assembly needs to be created. This function handles these tasks through interactions with .extensions, .loader.asmmaker, and .loader.uimaker Example: >>> from pyrevit.loader.sessionmgr import load_session >>> load_session() # start loading a new pyRevit session Returns: None """ # setup runtime environment variables sessioninfo.setup_runtime_vars() # the loader dll addon, does not create an output window # if an output window is not provided, create one if EXEC_PARAMS.first_load: output_window = _setup_output() else: from pyrevit import script output_window = script.get_output() # initialize timer to measure load time timer = Timer() # perform pre-load tasks _perform_onsessionloadstart_ops() # create a new session _new_session() # perform post-load tasks _perform_onsessionloadcomplete_ops() # log load time and thumbs-up :) endtime = timer.get_time() success_emoji = ':OK_hand:' if endtime < 3.00 else ':thumbs_up:' mlogger.info('Load time: %s seconds %s', endtime, success_emoji) # if everything went well, self destruct try: timeout = user_config.startuplog_timeout if timeout > 0 and not logger.loggers_have_errors(): if EXEC_PARAMS.first_load: # output_window is of type ScriptConsole output_window.SelfDestructTimer(timeout) else: # output_window is of type PyRevitOutputWindow output_window.self_destruct(timeout) except Exception as imp_err: mlogger.error('Error setting up self_destruct on output window | %s', imp_err) _cleanup_output() return sessioninfo.get_session_uuid()
def load_session(): """Handles loading/reloading of the pyRevit addin and extensions. To create a proper ui, pyRevit extensions needs to be properly parsed and a dll assembly needs to be created. This function handles these tasks through interactions with .extensions, .loader.asmmaker, and .loader.uimaker Example: >>> from pyrevit.loader.sessionmgr import load_session >>> load_session() # start loading a new pyRevit session Returns: None """ # initialize timer to measure load time timer = Timer() # perform pre-load tasks _perform_onsessionload_ops() # create a new session _new_session() # perform post-load tasks _perform_onsessionloadcomplete_ops() # log load time and thumbs-up :) endtime = timer.get_time() success_emoji = ':ok_hand_sign:' if endtime < 3.00 else ':thumbs_up:' logger.info('Load time: {} seconds {}'.format(endtime, success_emoji)) # if everything went well, self destruct try: from pyrevit.coreutils.console.output import output_window timeout = user_config.core.startuplogtimeout if timeout > 0 and not logger_has_errors(): output_window.self_destruct(timeout) except Exception as imp_err: logger.error( 'Error setting up self_destruct on output window | {}'.format( imp_err))
""" - Active Sheet Selection in ProjectBrowser or, if nothing selected, - Selection in Sheet-Selection-Dialog - Printer: Adobe PDF, """ __title__ = "PDFOut_Sheets" __author__ = "TBaumeister" __doc__ = "Test blabla" # for timing ------------------------------------------------------------------- from pyrevit.coreutils import Timer timer = Timer() import clr # import common language runtime .Net Laufzeitumgebung fuer .Net-anwendungen. / #um auf .Net Anwendungen zuzugreifen from System.Collections.Generic import List #clr.AddReference("RevitAPI") # .dll file from Autodesk.Revit.DB import * # FilteredElementCollector, OfClass, BuiltInCategory, Transaction, TransactionGroup import pyrevit from pyrevit import forms from rpw.ui.forms import FlexForm, Label, ComboBox, TextBox, \ Separator, Button, CheckBox, Alert import os import sys pyt_path = (r'C:\Program Files (x86)\IronPython 2.7\Lib') # must be imported in Dynamo Python node, see video GuiTalarico sys.path.append(pyt_path)
# coding: utf8 # VERSION ANTIGUA, NO USAR!!! """Inscribe la superficie neta de acabado vertical de las habitaciones, la parte de esa superficie perteneciente a tabiques de pladur, y la longitud de los rodapiés.\ Son necesarios 4 parámetros instancia de habitación en el proyecto: PARED NETA (Área), PARED NETA CARTON YESO (Área),\ RODAPIE (Longitud), CUARTO HUMEDO (Sí/No), y 2 parámetros de tipo de muro: EXCLUIDO (Sí/No), CARTON YESO (Sí/No),\ que indican si el muro tiene acabado y si el tipo de muro va hidrofugado cuando da a un cuarto húmedo, respectivamente. Ignora habitaciones con área 0 (not enclosed, not placed).\ De momento sólo funciona en la fase New Construction/Nueva construcción, que debe existir.""" #pyRevit info __title__ = 'Paredes Netas\ny Rodapiés' __author__ = 'Carlos Romero Carballo' from pyrevit.coreutils import Timer timer = Timer() import Autodesk.Revit from Autodesk.Revit.DB import * doc = __revit__.ActiveUIDocument.Document uidoc = __revit__.ActiveUIDocument #Phases (DE MOMENTO COGE 'NEW CONSTRUCTION' o 'NUEVA CONSTRUCCIÓN', AÑADIR SELECTOR) for ph in doc.Phases: if ph.Name == 'New Construction' or ph.Name == 'Nueva construcción': phase = ph break def existe(carp,phase): creada = doc.GetElement(carp.CreatedPhaseId).GetParameters("Sequence Number")[0].AsInteger() <= phase.GetParameters("Sequence Number")[0].AsInteger() no_demo = doc.GetElement(carp.DemolishedPhaseId).GetParameters("Sequence Number")[0].AsInteger() > phase.GetParameters("Sequence Number")[0].AsInteger() if carp.DemolishedPhaseId.IntegerValue != -1 else True return creada and no_demo
"""Inscribe en el parametro "MED_Net vertical finish room area" de todas las habitaciones del modelo el area neta de acabados verticales.""" """Se cruzan las caras verticales de la geometria de la habitacion con las caras verticales de los muros que forman sus boundaries. No funciona para habitaciones para las que Revit no puede crear geometria.""" __title__ = 'Room Geometry\nCheck' __author__ = 'Carlos Romero' #for timing from pyrevit.coreutils import Timer timer = Timer() from Autodesk.Revit.DB import Transaction, FilteredElementCollector, BuiltInCategory import Autodesk.Revit.DB as DB import clr doc = __revit__.ActiveUIDocument.Document uidoc = __revit__.ActiveUIDocument rooms = DB.FilteredElementCollector(doc).OfCategory(BuiltInCategory.OST_Rooms) flag = False for e in rooms: try: a = e.Geometry except: print("No geometry in room number " + str(e.Number)) flag = True if not flag: print("All model rooms have geometry.")
# -*- coding: utf-8 -*- """Alinea scope boxes, secciones y alzados a muros, model lines y rejillas. Se selecciona primero la referencia y luego la vista o scope box.""" #pyRevit info __title__ = 'Alinear Vistas\ny Scope Boxes' __author__ = 'Carlos Romero Carballo' from pyrevit.coreutils import Timer timer = Timer() import clr clr.AddReference('RevitAPI') from Autodesk.Revit.DB import * import Autodesk.Revit.UI.Selection doc = __revit__.ActiveUIDocument.Document uidoc = __revit__.ActiveUIDocument try: one = uidoc.Selection.PickObject( Autodesk.Revit.UI.Selection.ObjectType.Element) two = uidoc.Selection.PickObject( Autodesk.Revit.UI.Selection.ObjectType.Element) first = doc.GetElement(one) second = doc.GetElement(two) # normal of wall, line or grid if first.Category.Name == "Walls": normal = first.Orientation elif first.Category.Name == "Grids": normal = XYZ(first.Curve.Direction[1], -first.Curve.Direction[0],
#IMPORTS #for timing from pyrevit.coreutils import Timer from pyrevit.output import charts from pyrevit import script timer = Timer() #for the script to work import math import clr import sys import Autodesk.Revit.DB as DB from Autodesk.Revit.DB import * #FUNCTIONS #function that transforms project north 2D normals into real north 2D normals, given the angle between project and real north. def project_to_real_north(x, y, radians): newX = x * math.cos(radians) + y * math.sin(radians) newY = -x * math.sin(radians) + y * math.cos(radians) return round(newX, 4), round(newY, 4) #function that assigns an orientation to a 2D vector according a compass rose. def vector_orientation(x, y): if x <= 0.3826 and x >= -0.3826 and y <= 1 and y >= 0.9238: return "North" elif x < 0.8660 and x > 0.3826 and y < 0.9238 and y > 0.5000: return "Northeast"
engine = IronPython.Hosting.Python.CreateEngine(options) engine.SetSearchPaths(List[str]([PYTHON_LIB_DIR, MAIN_LIB_DIR])) runtime = engine.Runtime return engine, runtime def shutdown(runtime): runtime.Shutdown() engine_times = [] output_times = [] for idx in range(1, MAX_TESTS): engine, runtime = make_engine() engine_timer = Timer() run(engine, runtime) eng_time = engine_timer.get_time() shutdown(runtime) engine_times.append(eng_time) output_timer = Timer() print('Engine {}: {}'.format(idx, eng_time)) output_times.append(output_timer.get_time()) chart = this_script.output.make_line_chart() # chart.options.scales = {'xAxes': [{'ticks': {'fixedStepSize': 5}, 'type': 'category', 'position': 'bottom'}], # 'yAxes': [{'ticks': {'fixedStepSize': 10}}]} chart.data.labels = [x for x in range(0, MAX_TESTS + 1)]
# -*- coding: utf-8 -*- """Modifica los colores de las capas de los DWG importados si sus nombres están en la plantilla "plantilla_capas.csv" (primera columna nombres, segunda columna código 0-255 de color) incluida en la misma carpeta que el script.""" __title__ = 'Aplicar Colores de\nPlantilla a DWG' __author__ = 'Carlos Romero Carballo' from pyrevit.coreutils import Timer timer = Timer() import csv import clr import os.path import Autodesk.Revit.DB as DB from Autodesk.Revit.DB import * doc = __revit__.ActiveUIDocument.Document uidoc = __revit__.ActiveUIDocument plantilla_dwg_path = "C:\ProgramData\pyRevit\pyRevit-v45\pyRevit\extensions\pyRevitTABim.extension\TABim.tab\Utilidades.panel\Colores DWG.pushbutton\dwg_to_rgb.csv" plantilla_capas_path = "C:\ProgramData\pyRevit\pyRevit-v45\pyRevit\extensions\pyRevitTABim.extension\TABim.tab\Utilidades.panel\Colores DWG.pushbutton\plantilla_capas.csv" cads_categories = [ cat for cat in doc.Settings.Categories if cat.Name.ToString().endswith(".dwg") ] capas_dwg = [ item for sublist in [ cat.SubCategories for cat in doc.Settings.Categories if cat.Name.ToString().endswith(".dwg") ] for item in sublist ]
"""Inscribe en el parametro "ORIENTACION" la orientacion de la normal de los muros""" __title__ = 'Orientacion\nde Muros' __author__ = 'Carlos Romero' #for timing from pyrevit.coreutils import Timer timer = Timer() from Autodesk.Revit.DB import Transaction, FilteredElementCollector, BuiltInCategory import Autodesk.Revit.DB as DB import clr doc = __revit__.ActiveUIDocument.Document uidoc = __revit__.ActiveUIDocument walls = DB.FilteredElementCollector(doc).OfCategory( BuiltInCategory.OST_Walls).WhereElementIsNotElementType().ToElements() new_walls = [] ori_x = [] ori_y = [] print("Muros en el modelo: " + str(len(walls))) for wall in walls: try: ori_x.append(round(wall.Orientation.Normalize().X, 4)) ori_y.append(round(wall.Orientation.Normalize().Y, 4)) new_walls.append(wall) except: print("No ha podido sacar la orientacion de uno de los muros.")
#IMPORTS #for timing from pyrevit.coreutils import Timer from pyrevit.output import charts from pyrevit import script timer = Timer() #for the script to work import math import clr import sys import Autodesk.Revit.DB as DB from Autodesk.Revit.DB import * #FUNCTIONS #function that transforms project north 2D normals into real north 2D normals, given the angle between project and real north. def project_to_real_north(x, y, radians): newX = x * math.cos(radians) + y * math.sin(radians) newY = -x * math.sin(radians) + y * math.cos(radians) return round(newX, 4), round(newY, 4) #function that assigns an orientation to a 2D vector according a compass rose. def vector_orientation (x, y): if x <= 0.3826 and x >= -0.3826 and y <= 1 and y >= 0.9238: return "North" elif x < 0.8660 and x > 0.3826 and y < 0.9238 and y > 0.5000: return "Northeast" elif x <= 1 and x >= 0.8660 and y <= 0.5000 and y >= -0.3583: return "East"