Posts

Checking files on startup

A few of the files for which I'm responsible at work need to be updated regularly to ensure team members and clients always have access to the latest data. The problem is that each file has a different "expiration", and I'm quite a forgetful person. To solve this issue, I created a simple script to check the last time my files were edited. If a file is expired, I get an alert to update it. This script runs in the background every time I start my computer, so I don't notice it when I don't need it. To do this, let's create a new python file. Rather than ending our file in .py , however, we'll use .pyw . This will ensure our script runs without a console window, meaning it will go unnoticed unless it finds an issue for us to address. Next, we'll add our imports and global variables. We'll create a list of the file paths we want to check and, crucially, we'll establish the maximum age of the files. To kee...

Create Dimensions - Rooms

Image
In this post, we discussed creating dimensions with the Revit API. But we only discussed dimensioning walls. Sometimes, however, we want to dimensions to include other elements - balconies, for instance, which are not typically drawn with wall elements. In this case, we can use our room separation lines. def r2(num): return round(num, 2) doc = DocumentManager.Instance.CurrentDBDocument rooms = FilteredElementCollector(doc).OfCategory(BuiltInCategory.OST_Rooms).WhereElementIsNotElementType().ToElements() Once that's done, we can iterate through all these lines to find their maximum extents (for the purposes of this post, I'll assume we just want to dimension the rooms' x extents). leftmost_x = float('inf') rightmost_x = 0 line_left = None line_right = None for line in roomlines: info = line.Location.Curve direction = info.Direction origin = info.Origin if r2...

AutoHotKey

Over the weekend, I spent some time exploring the potential of AutoHotKey . This programme was not designed specifically for architects, but it has useful applications in the field nevertheless. Essentially, this is a programming language that lets users code their own keyboard shortcuts. The AHK file has to be open for it to work, but by appending a script file to the startup folder (accessable on windows by hitting Windows+R and entering "shall:startup" into the resulting pop-up window), you can open and run it in the background whenever your computer starts up. I've only spent a couple of hours playing around with it, but already, I've created a few cool shortcuts I'd like to share. Let's start with a super simple one: #q:: { Send "benjaminjamesrowley@gmail.com" } Let's go line by line: Declare a keyboard combination. I've chosen Windows (indicated by the #) + Q. The double colon indic...

Exporting Sheets as PDFs

In this post, we discussed the automatic creation and population of view sheets. We can also automate the export those sheets as PDFs - in my company, for instance, we do this every week to ensure that our clients, who do not use Revit itself, always have access to relatively up-to-date design information. To start, we'll collect all the sheets in our file and filter for the ones we want to export. There are two things to note here. Firstly, regardless of how many sheets we want to export, we need a list (if we only want one, we'll have a list containing a single item). Secondly, the list should not contain the sheet objects themselves but their IDs. doc = DocumentManager.Instance.CurrentDBDocument sheets = FilteredElementCollector(doc).OfClass(ViewSheet).ToElements() names_of_sheets_to_export = ["Lorem", "Ipsum"] sheets_to_export = [sheet.Id for sheet in sheets if sheet.Name in names_of_sheets_to_export] Once we have...

Using Excel in Automations

Let's say you want your non-coding coworkers to be able to control certain results of your scripts. There are several ways to do this, but by far the simplest is to create a shared Excel file. Your coworkers can input values into this file, which can then be read by your script at execution time. There are countless possible use-cases for this method, but for this example, we'll keep it simple and look at creating levels at certain elevations. Setting Up Excel Before we create any code, we need to set up our Excel file. Make sure to save it somewhere your coworkers can access. We'll create two columns, one called "LevelName" and the other "Elevation". We'll call our sheet "New Level Names". NOTE: Once the file is created, we'll want to add guards to make sure our script runs smoothly. We don't want people to be able to add non-integers to the Elevation column, for instance. For more information on protectin...

Creating and Editing Schedules

Schedules can be created and adjusted via the Revit API. In this example, we'll keep things simple and create a schedule that lists all the walls in our file and their lengths. To do this, we'll use ViewSchedule.CreateSchedule(), which takes three arguments: The document we want to add our sheet to. The Element ID of the category we want to analyse. The Element ID of the area scheme we want to use. We won't be looking at areas in this post, so we'll pass an invalid element ID to skip it. doc = DocumentManager.Instance.CurrentDBDocument wall_category_id = ElementId(BuiltInCategory.OST_Walls) TransactionManager.Instance.EnsureInTransaction(doc) new_schedule = ViewSchedule.CreateSchedule(doc, wall_category_id, ElementId(-1)) #ElementId(-1) is an invalid ID. It is used to skip the area scheme. TransactionManager.Instance.TransactionTaskDone() That should have created a new schedule. If we open that schedule, howeve...

Creating and Populating View Sheets

View sheets can be created and managed automatically using the Revit API. Creating a Sheet To start, we'll keep things simple and discuss adding a sheet to a file. To do that, we'll use the ViewSheet.Create() method, which takes two arguments: The document we want to add our sheet to. The ID of the title block we want the view sheet to use. doc = DocumentManager.Instance.CurrentDBDocument #Get the ID of the TitleBlock we want to create titleblocks = Fec(doc).OfCategory(Bic.OST_TitleBlocks).WhereElementIsElementType() for titleblock in titleblocks: name = titleblock.get_Parameter(BuiltInParameter.SYMBOL_NAME_PARAM).AsString() if name == "lorem_ipsum": target_titleblock_id = titleblock.Id break #Create a ViewSheet of the established target type TransactionManager.Instance.EnsureInTransaction(doc) new_sheet = ViewSheet.Create(doc, target_titleblock_id) TransactionMana...