Here’s the scenario – you’re heading out of town for a much deserved vacation. Before you leave, you spend some time cleaning up your project’s Revit model. You delete all the extraneous views, purge out unused families and compact the central file. You leave the office on Friday with your model looking neat and tidy.
Fast forward one week. You get back to the office on Monday morning and open up the model. “What the. . . ” you exclaim as you see the project browser. It looks like a troop of monkeys got into the office and went bananas creating new views. None of the views follow the naming convention. There are copies of copies of views. Some of the names aren’t even in English. And who thought “Zzyzx” was a good name for a view?
Delete Unused Views
Fortunately it’s easy to clean out all the unused views in your Revit model. The following Revit macro deletes all views in the current project that are not on a sheet or are not named with the specified prefix. The macro works with all views, including dependent views. It does not delete schedules (at least not yet).
The macro starts by getting all the views in the current model file. It then loops through the views and checks if the view is placed on a sheet. If the view is not on a sheet, the macro checks if the view name has a particular prefix. In this example, it checks for views beginning with “working”. Note that you can edit the code to use any prefix you want – just change the value of the “viewPrefix” variable as shown below.
If the current view does not have the prefix and is not on a sheet, it can be deleted. The macro adds the view to a list of views to delete. Once all the views have been checked, the macro goes through the list of views to delete and removes each one from the model file.
Dependent views are a little tricky so the macro takes two passes through the views. The first pass removes all dependent child views that are not on a sheet or do not have the prefix. The second pass removes any parent views that do not have any child views.
Once all the clean-up is done, the macros displays the list of the views that have been deleted.
Who doesn’t like keeping their Revit model nice and clean? The macro takes only a few seconds to run and accurately removes all the unneeded views. No more guesswork required. Download the macro below and you can easily delete unused views from your Revit model.
Download the Macro
The macro is written in VB.Net. In this example, I use “working_” as the prefix but you can easily edit to code and add your own prefix for files you want to keep in addition to those already on sheets. As you’ll see, the code is pretty straightforward.
You can download the macro (in Revit 2015 format) from the ArchSmarter Revit Macro Library. To access the library, sign up for ArchSmarter updates in the form below.
Let me know what you think about the macro and leave comment in the box below.