Upgrade your web presence with Framer

Elevate Your Experience.
Get Started Now.

Elevate Your Experience.
Get Started Now.

Schedule a call with Goran B.

Schedule a call with Goran B.

Babarogic © 2023. Designed by Goran Babarogic

Babarogic © 2023. Designed by Goran Babarogic

Babarogic © 2023. Designed by Goran Babarogic

Managing Revit Events: Guardian for Revit Projects

Managing Revit Events: Guardian for Revit Projects

Managing Revit Events: Guardian for Revit Projects

Strategies for monitoring model changes and utilizing event hooks throughout the project.

Ensuring smooth collaboration between multiple disciplines in a Revit project depends on the effectiveness of shared coordinates that maintain positioning consistency between linked models. To protect against inadvertent changes to these shared coordinates, it would be prudent to investigate the implementation of warning mechanisms similar to those used for the project base point.

Similar to the protective measures applied to the project base point, providing prompts or warnings when attempting to modify shared coordinates could serve as a vital reminder for users. These warnings could effectively communicate the potential consequences on linked models, encouraging users to exercise careful and thoughtful decision-making.

For example, when a user attempts to relocate a protected project base point, a warning message immediately warns them not to do so. Similarly, attempting to remove a project basepoint would trigger a protective command message and prompt users to enter a designated password to continue the action.

Monitoring Model Changes

  • large size families

  • Importing cad

  • Inplace family

  • saving and syncing activitie

Tracking changes within a Revit model is essential for maintaining an audit trail and identifying potential security breaches. Utilize Revit's built-in version control features to monitor revisions and track modifications made by users. Additionally, consider integrating third-party auditing tools that provide comprehensive insights into model changes, including user activity logs and revision histories. By proactively monitoring model changes, organizations can detect unauthorized alterations and take appropriate corrective actions.

What is the hook events?

Hooks provides a structure that listens for certain events and triggers defined functions when these events occur. For example, you can have a function run when an item is selected or a command is started.

# -*- coding: utf-8 -*-

# dependencies
import clr
clr.AddReference('System.Windows.Forms')
clr.AddReference('IronPython.Wpf')
clr.AddReference('System.Drawing')
import json
import math
import re
from collections import namedtuple

# .NET Imports
clr.AddReference('System') 
from System.Collections.Generic import List

# import WPF creator and base Window
import System
clr.AddReference("System.Net")
from System.Net import WebClient, HttpRequestHeader

import webbrowser
import wpf
from System import Windows
from pyrevit import revit, EXEC_PARAMS, forms, script    
from Autodesk.Revit.UI import TaskDialog
from pyrevit.forms import ask_for_string
from pyrevit import script

from Autodesk.Revit.DB import FilteredElementCollector, BuiltInCategory, Transaction
from pyrevit import revit, EXEC_PARAMS

import os, sys, datetime         
from Autodesk.Revit import DB
from Autodesk.Revit.DB import *  
from Autodesk.Revit.UI import *  
from Autodesk.Revit.DB.Architecture import *

from System.Drawing import Image, Point
from System.Windows.Forms import Application, Form, PictureBox, FormStartPosition
import System.Windows.Forms as WinForms
import System.Drawing as Drawing

from datetime import datetime

# variables
sender = __eventsender__ # UI Application
args = __eventargs__ 

doc = revit.doc

logger = script.get_logger()
xamlfile = script.get_bundle_file('AboutWindow.xaml')


#---------------------------------------------------------------------------------------------------------
# airtable part
client = WebClient()
AIRTABLE_BASE_ID = "appLys60ZA6crVha1"
AIRTABLE_TABLE_NAME = "revit-table"
AIRTABLE_API_KEY = "patYXUjpCrz1g1jWl.63ca523eb1d45cd66a801662a2849186cdba9be4d5b43e2d563a00d6438adbbf"

url = "https://api.airtable.com/v0/{}/{}".format(AIRTABLE_BASE_ID, AIRTABLE_TABLE_NAME)

name = __revit__.Username
app   = __revit__
version = app.VersionNumber
request = str("Coordinates")


# Bugünün tarihini al
gun = datetime.today()
date = gun.strftime("%Y-%m-%d")


class AboutWindow(Windows.Window):
    def __init__(self):
        wpf.LoadComponent(self, xamlfile)
        # self.logo_img.Source = self._get_logo_image()
 
    #get logo png from root folder
    def _get_logo_image(self):
        print("test")
        return
        path = os.path.dirname(os.path.abspath(__file__))
        logo = os.path.join(path, 'icon.png')

        yellowbitmap = System.Windows.Media.Imaging.BitmapImage()
        yellowbitmap.BeginInit()
        yellowbitmap.UriSource = System.Uri(logo)

        try:
            yellowbitmap.EndInit()       
            return yellowbitmap   
        except System.IO.FileNotFoundException as e:
            logger.error(e.Message)
        else:
            return yellowbitmap

    def handleclick(self, sender, args):
        self.Close()
    
def make_request(name,request,version,date):
    data = {
        "records": [
            {
                "fields":{
                    
                    "Name": name,
                    "Request": request, 
                    "Version" : version,
                    "Date" : date
                }
            }
        ]
    }
    client.Headers[HttpRequestHeader.ContentType] = "application/json"
    client.Headers[HttpRequestHeader.Authorization] = "Bearer {}".format(AIRTABLE_API_KEY)

    client.UploadString(url,json.dumps(data))



make_request(name,request,version,date)

args = EXEC_PARAMS.event_args


#---------------------------------------------------------------------------------------------------------
#Getting PBP Values
#pbp = FilteredElementCollector(doc).OfCategory(BuiltInCategory.OST_ProjectBasePoint).ToElements()
"""		
# Get pbp values
pbp_ew = pbp.get_Parameter(BuiltInParameter.BASEPOINT_EASTWEST_PARAM).AsDouble() * 304.8
pbp_ns = pbp.get_Parameter(BuiltInParameter.BASEPOINT_NORTHSOUTH_PARAM).AsDouble() * 304.8
pbp_el = pbp.get_Parameter(BuiltInParameter.BASEPOINT_ELEVATION_PARAM).AsDouble() * 304.8
pbp_an = pbp.get_Parameter(BuiltInParameter.BASEPOINT_ANGLETON_PARAM).AsDouble() * 180/math.pi
"""	

try:
    mod_elems = __eventargs__.GetModifiedElementIds()
    for i in mod_elems:
        ele = doc.GetElement(i)
        elem = ele.ToString()
        if elem == "Autodesk.Revit.DB.ProjectLocation":
        
            #let's show the window (model)
            AboutWindow().ShowDialog()
            #output = script.get_output()
        else:
            continue
except:
    print("okey")

Connect with Database