Posts

Showing posts from November, 2024

Overwriting Parameters

To overwrite parameters via the Revit API, we need to get the parameter, then pass it a value of the type it expects. If you don't already have it, I would recommend installing Revit Lookup . This tool is always useful, but for what we're doing here, I'd go so far as to say it's virtually essential. In this example, let's pretend we have a big meeting in Germany, requiring us to change all our room names. We'll start by creating a simple dictionary of the room names we need to change. eng_to_de_roomnames = { "Bedroom": "Schlafzimmer", "Living Room": "Wohnzimmer", "Kitchen": "Kueche" } Then, we'll collect all the rooms in our document and iterate through them. (NOTE: When working iterating through rooms, it's always a good idea to check that the room has a location before trying to do anything to it. This is because when a room is deleted...

Manage Global Parameters

Global Parameters can be renamed, deleted, or added or changed via the Revit API. This is especially useful in office contexts, where it is sometimes necessary to update dozens of parameters across hundreds of files, a task that would take us (or a student) days to finish by hand. Let's say we want to change the global parameters in our office so they match the following: Apple: 10 mm Banana: "Example String" Cherry: Yes We'll start by converting that into a python dictionary: global_parameters_should_be = { "Apple": { "Type": "Length", "Value": 10/304.8 #Revit always works in feet, regardless of your project settings. }, "Banana": { "Type": "String", "Value": "Example String" }, "Cherry": { "Type": "Boolean"...

Change Dimension Type

Image
In this post, we discussed creating dimensions with the Revit API. But that script doesn't give us any control over dimension types, which might be an issue. The first time I ran it, for instance, it returned a dimension with nine decimal places: Today, we'll talk about creating and customising a new dimension type, so we can have our new dimensions look exactly as we'd like. For the sake of argument, we'll say we want to convert our dimension to millimetres, with one decimal place. Unfortunately, it's not possible (as far as I know) to create a new dimension type from nothing. We need to duplicate an existing type and edit its format options. (For the sake of simplicity, we'll assume that all our existing dimensions are (and should remain) of the same type. doc = DocumentManager.Instance.CurrentDBDocument dimensions = FilteredElementCollector(doc).OfCategory(BuiltInCategory.OST_Dimensions).WhereElementIsNotElementType()...

Create dimensions

Image
It is possible to automate the creation of dimensions in Revit. This process is highly customisable, but for the sake of argument, let's say we want to dimension the horizontal extents of a series of walls (to learn how to dimension room separation lines, click here ). To do this, we'll be using the NewDimension() method, which takes four arguments: View. In this case, we'll be using the doc.ActiveView, but you can specify any view you'd like. A line. This line will form the dimension. We will create this line before creating the dimension. A reference array. We need to tell the dimension which wall planes to base itself on. That way, if the wall moves, the dimension moves too. Dimension type. This input is optional. To keep this tutorial as simple as possible, we'll ignore this for now. Before we begin, let's set up a simple rounding function (to deal with tiny imprecisions in our model), and an instance of Opt...

Check which user owns an element in a shared model

When working with the Revit API in shared models, we are unable to execute commands on elements that are owned by other users. The following code snippet shows how to handle this issue. For the sake of arguement, let's imagine we want to perform an action on our walls. doc = DocumentManager.Instance.CurrentDBDocument walls = FilteredElementCollector(doc).OfCategory(BuiltInCategory.OST_Walls).WhereElementIsNotElementType() owned_walls = [] unowned_walls = [] for wall in walls: wall_id = wall.Id tooltipInfo = WorksharingUtils.GetWorksharingTooltipInfo(doc, wall_id) owner = tooltipInfo.Owner #If you're interested, you can also check who created the element and who edited it last. creator = tooltipInfo.Creator lastchangedby = tooltipInfo.LastChangedBy if owner != "" and owner != "lorem.ipsum": #The element is owned (it doesn't belong to an empty string), and it...