Say Goodbye to Unwanted Materials in Revit: Deleting Elements with a Selection Dialogue

Revit is a powerful tool for building design and construction, but with great power comes great responsibility. Keeping your Revit projects tidy and efficient can be a daunting task, especially when it comes to purging unwanted elements. Revit does come with an out-of-the-box feature Purge Unwanted to purge items, but it doesn’t allow bulk deleting of custom-picked elements.

To solve this problem, we can turn to Dynamo, a visual programming platform that allows us to automate tasks in Revit. By creating a Dynamo script or workflow, we can first get all the materials used in the project and then let the user pick the elements or materials that need to be deleted. The script filters out the selected materials and deletes them in bulk.

List.FilterBySelection from Springs package

Delete Unwanted Materials Dynamo Graph

By creating our own Dynamo workflows around this, we can delete other unplaced elements in bulk, such as views, floor plans, sections, legends, schedules, spaces, rooms, scope boxes, imported files, and more.

By using Dynamo to automate the process of purging unwanted elements in Revit, we can save time and improve the efficiency of our workflow. So why not give it a try and see how it can streamline your Revit projects?

Python 1: Get All Materials
This piece of code retrieves all the material elements and their names in the project.

# Import the necessary packages
import clr
clr.AddReference('RevitAPI')
from Autodesk.Revit.DB import *
clr.AddReference('RevitServices')
from RevitServices.Persistence import DocumentManager

# Get the Revit document
doc = DocumentManager.Instance.CurrentDBDocument

# Get all the materials in the project
materials = FilteredElementCollector(doc).OfClass(Material)
mats = FilteredElementCollector(doc).OfClass(Material).ToElements()
# Create lists to store the material names and IDs
material_names = []
material_ids = []

# Loop through the materials and retrieve their names and IDs
for material in materials:
    material_names.append(str(material.Id) + " - " + material.Name)

# Define the outputs
OUT = mats, material_names

Python 2: Filter List

The Python 2: Filter List node is taken from the List.FilterBySelection custom node by spring nodes by Dimitar Venkov. This Python code defines a custom form with checkboxes that allow the user to select elements. The code adds references to the necessary libraries, defines a few functions, and then creates the form using the CheckBoxForm class. The form includes buttons to check or uncheck all the elements, and to save the selected elements. This code can be used in Dynamo scripts to enable user selection of elements for further processing.

#Copyright(c) 2016, Dimitar Venkov
# @5devene, dimitar.ven@gmail.com

import clr
clr.AddReference('System.Windows.Forms')
clr.AddReference('System.Drawing')
from System.Drawing import Point, Color, Font
from System.Windows.Forms import *

def tolist(obj1):
	if hasattr(obj1,"__iter__"): return obj1
	else: return [obj1]
	
def hasInd(l1, i):
	try: l1[i] ; return True
	except: return False

class CheckBoxForm(Form):
	def __init__(self, cm1):
		self.Text = "Filter By Selection"
		self.Width = 400
		self.BackColor = Color.FromArgb(40,40,40)
		self.output1 = []
		self.ControlBox = False
		self.TopMost = True
		self.FormBorderStyle = FormBorderStyle.FixedDialog
		self.StartPosition = FormStartPosition.CenterScreen
		
		self.label = Label()
		self.label.Text = cm1
		self.label.Location = Point(5, 5)
		self.label.ForeColor = Color.FromArgb(234,234,234)
		self.label.Font = Font("Calibri", 10)
		self.label.AutoSize = True
		self.Controls.Add(self.label)

		self.button1 = Button()
		self.button1.Text = 'Save Selection'
		self.button1.AutoSize = True
		self.button1.ForeColor = Color.FromArgb(234,234,234)
		self.button1.Font = Font("Calibri", 10)
		self.button1.Click += self.save
		self.Controls.Add(self.button1)

		self.button2 = Button()
		self.button2.Text = 'Uncheck All'
		self.button2.AutoSize = True
		self.button2.ForeColor = Color.FromArgb(234,234,234)
		self.button2.Font = Font("Calibri", 10)
		self.button2.Click += self.uncheckAll
		self.Controls.Add(self.button2)

		self.button3 = Button()
		self.button3.Text = 'Check All'
		self.button3.AutoSize = True
		self.button3.ForeColor = Color.FromArgb(234,234,234)
		self.button3.Font = Font("Calibri", 10)
		self.button3.Click += self.checkAll
		self.Controls.Add(self.button3)
		
		self.panel1 = Panel()
		self.panel1.Location = Point(5, 31)
		self.panel1.Width = 370
		self.panel1.BackColor = Color.FromArgb(53,53,53)
		self.panel1.ForeColor = Color.FromArgb(234,234,234)
		self.Controls.Add(self.panel1)
		
	def add_check(self, text1, y1, b1):
		self.check1 = CheckBox()
		self.check1.Text = text1
		self.check1.Location = Point(5, y1)
		self.check1.AutoSize = True
		self.check1.Font = Font("Calibri", 10)
		self.check1.Checked = b1
		self.panel1.Controls.Add(self.check1)
	
	def btn_adjust(self,y1):
		if y1 > 700:
			y1 = 700
			self.panel1.AutoScroll = True
			self.panel1.Focus()
		self.panel1.Height = y1
		self.button1.Location = Point(5,   y1 + 38)
		self.button2.Location = Point(170, y1 + 38)
		self.button3.Location = Point(275, y1 + 38)
		self.Height = y1 + 130
			
	def save(self, sender, event):
		ctrl1 = self.panel1.Controls
		count1 = ctrl1.Count
		loc = 0
		self.output1 = [c.Checked == 1 for c in ctrl1]
		#for i in xrange(count1):
		#	if ctrl1[i].Checked == 1:
		#		self.output1.append(l1[loc])
		#	else:
		#		self.output2.append(l1[loc])
		#	loc += 1
		self.Close()
	
	def uncheckAll(self, sender, event):
		ctrl1 = self.panel1.Controls
		count1 = ctrl1.Count
		for i in xrange(count1):
			ctrl1[i].Checked = False
	
	def checkAll(self, sender, event):
		ctrl1 = self.panel1.Controls
		count1 = ctrl1.Count
		for i in xrange(count1):
			ctrl1[i].Checked = True

l1 = tolist(IN[0])
if IN[1] == None: names = None
else: names = tolist(IN[1])

form = CheckBoxForm(IN[2])
y1 = 5
for i in xrange(len(l1)):
	try:
		if hasInd(names, i): val1 = names[i].ToString()
		else: val1 = l1[i].ToString()
		form.add_check(val1, y1, IN[3])
		y1 += 25
	except: pass
form.btn_adjust(y1)

Application.Run(form)
OUT = form.output1#, form.output2
Application.Exit()

Export Data to an Existing Excel Template

Ever wondered how to export data from Revit or any source for that matter to an existing Excel file where you already have some formatting done? It can be a bit winding task to first export your data to an intermediary blank Excel sheet and then copy/paste or link the cells or range to your original Excel template file.

This workflow here does not require any custom node or high-level coding — just a couple of out-of-the-box nodes to get your job done in a few seconds.

A sample Excel workbook with some formatting and formula applied
This Dynamo graph could be used in any Dynamo for Revit version. List.Combine acts as a function.
Output Excel sheet with the data filled in respective places

This is how you can save precious time to export data to any existing Excel file without making any modifications to the formatting. You can re-run the Dynamo script after changing input data in order to make any further changes.

Text Case Changing in Revit

Dynamo can be used to perform basic text editing and formatting in bulk either in Autodesk Revit or any text information imported from other sources.

Image displaying changing the case of multiple text notes to Upper Case.

A simple dynamo workflow to change text case to lower case, upper case, title case, and separated by underscore.

How to use Dynamo Player?

Dynamo Player is a quick and easy way to run your Dynamo routines or scripts. It provides a visual user interface where you do not have to worry about all the nodes, wires, and the back-end stuff. It is just like any other music player to run the .dyn files. It proves to be most helpful when you have to run the same script over and over again in a Revit project.

To use the Dynamo Player:

  • Go to Manage > Dynamo Player
  • Browse the folder where all the Dynamo files (*.dyn) are kept.
  • Now all the scripts from the folder will be loaded to your current session.
  • This is a one-time set-up you can open Dynamo Player anytime to run any script directly without having to open Dynamo.

How do I enable my Dynamo scripts to run into Dynamo Player?

  • Open any Dynamo graph
  • Define all the inputs — right-click the node and select Is Input. Do not forget to rename the node.
  • Optional: Define all the outputs — right-click the node and select Is Output. Do not forget to rename the node.
  • Once you have set-up all the inputs and outputs in a Dynamo graph save the file. It is now ready to run on the Dynamo Player. 

Generate QR Codes with Dynamo

QR Code has been an essential tool in the design-to-fabrication or spooling process in construction industry to track and check the status of individual components that are manufactured or fabricated and shipped to project site for installation.

At a micro level these unique tags facilitates the 7D BIM, which caters to Facility or Asset Managment Applications. COBie data population and extraction, BIM As-builts are parts and parcels of this process.

In essence, these optical labels, QR codes or Bar codes sticks to an item to bind the real-world component to a digital model component.

Here we are going to see how we can easily extract data out of Revit models and quickly create QR Codes.

QR Code Generation in Dynamo

Generating a QR Code in Dynamo

QR Coder on github

QR Code Parameter

For schedule preparation in Revit

Multiple QR Code Generate

Create multiple QR codes out of Revit data

QR Codes for Framing

Exported QR Codes from Dynamo

QR Coding of Revit Items

Components Scheduled with QR Codes in Revit

How to Install and Run Revit Python Shell

Revit Python Shell or RPS is a good way to write Python codes in Revit and create plugins. It’s a free script editor integrated into Revit API that gives you the benefit of seeing the result as you code.

Use it in combination with Revit Lookup. It has below three features.

  • Interactive Python Shell
  • Non-modal Shell: Not interfering with the Revit model
  • Deploy RpsAddin: Make plugins for Revit

Revit Python Shell in Revit

But first, we will see how to install RPS in Windows.

  1. Go to the RPS GitHub page and download the installer for your respective Revit version.
    Run the installer and check if the RPS appears on your Add-ins tab in Revit.
  2. If not, download the whole master code zip from the Github page.
  3. The installer would have created the below directory in your C drive.RPS install
  4. Go to the below location and make an ADDIN manifest file by pasting the code. Make sure to give it the right path of the RevitPythonShell.dll file from the previous step.
    <?xml version="1.0" encoding="utf-8" standalone="no"?>
    <RevitAddIns>
      <AddIn Type="Application">
        <Name>RevitPythonShell</Name>
        <Assembly>C:\Program Files (x86)\RevitPythonShell2019</Assembly>
        <AddInId>GENERATE_AND_INSERT_GUID_HERE</AddInId>
        <FullClassName>RevitPythonShell.RevitPythonShellApplication</FullClassName>
        <VendorId>RIPS</VendorId>
      </AddIn>
    </RevitAddIns>

ADDIN file

5. Unzip the downloaded revitpythonshell-master package from step 2 and copy the        contents of the folder revitpythonshell-master\revitpythonshell-master\RevitPythonShell\DefaultConfig and make a folder with RevitPythonShell2019 or whatever version the Revit version you want to work with and paste the contents into this folder at the path shown in the image below.

RPS download

Launch the target Revit version and accept the RevitPythonShell popup with Always Load. The RevitPythonShell ribbon should appear under Add-ins tab.

Making and Deploying RPS Addin

An RpsAddin refers to a Revit Addin that was written using the RevitPythonShell and then bundled for deployment using the “Deploy RpsAddin” feature of the RevitPythonShell.

RpsAddins allow you to easily deploy your scripts without having to install and configure RevitPythonShell on each machine. It does this by creating a Revit DLL that can be used as an Addin. This DLL will use some runtime glue code located in RpsRuntime.dll to provide IronPython integration for the Addin. The DLL also contains your scripts and a manifest for the addin as string resources.

In a future post, we’ll see to create and deploy an RPS addin. Till then, download the guidebook for Python Scripting with RPS from here.

Revit Worksets in Navisworks and Filtering Elements

Ever wondered how to filter out elements in Autodesk Navisworks Manage by their Revit worksets?

Worksets in Navisworks can give you greater control over your model data. You can perform various filtering, formatting on the worksets. It is also easier to extract parametric data out of Navisworks when you have clearly defined worksets.

Workset Selection Sets

Worksets in Revit

Worksets in Revit

Steps: 

  1. Export the 3D model in NWC format. Remember to keep the “Close NWC/NWD files on load” checkbox ticked while saving as *.nwc. Without this checked, the file lock is on and you cannot overwrite the file unless you close the current Navisworks file where it is appended to.

Exporting as NWC

Exporting as *.nwc

2. Append the file in Navisworks Manage. Select any element and right-click and make sure that the Set Selection Resolution is kept as the First Object. It will make the object path start at the highest level of objects below the layer node, if applicable.

Set Selection Resolution setting

Set Selection Resolution setting

3. You can see all the property data of the selected Revit element from the Properties panel in the Home ribbon. This is for our viewing purpose.

Properties in Navisworks

Properties in Navisworks

4. Now open Selection Tree panel (Ctrl+F12), and select Properties from the drop down menu.

As worksets are a property of the elements, go to Element > Workset.
Here you can find all the worksets (only those that contain elements) from your Revit project.

Worksets selection

Workset Selection

5. You can right-click and tick Hide Unselected to isolate the elements of the specific workset.

Click on Selection Inspector and it will show all the elements of that particular workset. Click Save Selection for all the entities in Workset.

Save worksets as set

Save Selection for Workset

Now you can find all the worksets under the Sets in the Selection Tree. All the filtering and sorting could be performed on these worksets.

Workset Selection Sets

Workset Section Sets

Tip: To sort or filter elements of different categories based on their parametric values Find Items is a pretty handy feature.

Go to View > Windows > Find Items

Find Items

Find Items for filtering

You can search in the already defined worksets or other selection sets to narrow down the filtering.

Revit Warnings Messages

Mitigating warnings in Revit could be a pretty daunting task. It can severely impact your model in a long run if left unchecked.

You can find all the warnings pertaining to your current project under
Manage tabInquiry panel (Review Warnings)

This tool is not enabled if there are no warning messages.

Warnings in Revit

These warnings could essentially be divided into three severity levels.

1. Ignorable: Warnings that are primarily informative and can be ignored.

2. Serious: Can be ignored but should be addressed in due course.

3. Critical: Must be resolved to keep the file functioning properly. You can find warning elements by their element ID number.

Listed below are all possible Revit warning types that could creep up in a Revit model or family environment.
e.g. A warning of type Elements have duplicate “Value” values could manifest itself in the form of Elements have duplicate “Mark” values in a project.
Continue reading →

3D printable files in Dynamo

STL and OBJ files have become a standard in the 3D printing industry. Many 3D modeling and computer graphics programs such as Autodesk Maya, Blender, Sketchup, Cinema 4D can produce these models in a pretty nifty manner.

For color 3D printing with precise mesh encoding, OBJ files prove to be a useful format while preserving the precise mesh encoding. You may get yourself a free 3D model from Oyonale.

You can see the 3D model in any free 3D object viewer. The 3D Viewer from Microsoft is a great application that comes with Windows 10.

Required Custom Packages:

  • Spring Nodes
  • Orchid