[Clean Project by Form]
I’m sure we have all been in the situation with Revit where a project becomes so bloated that it struggles to get out of bed in the morning. This can happen for a lot of reasons, and there are plenty of ways that projects can be cleaned up through purging and management. This script is useful to help with management of bloated projects by deleting some of the elements that build up and bog it down. Specifically , it will find elevation markers that are no longer being used, reference lines that are unnamed and don’t host elements, and views that are not placed or needed.
The script works by collecting the elements we want to clean, filtering them based on specific parameters and them sending them through a Windows Form Python script to double check we want to clean them. The reason I have done this is to put in a bit of padding around the Revit API Delete command. It is always very risky putting a delete method in any script so I’ve set up this check to make the user is 100% sure of what they are about to delete.
There is plenty of opportunity to adapt the script to collect and clean up other elements that fit your needs so please feel free to download the file at the bottom of the page and give it a whirl. Also, one bug I have found is if you try to delete the view that your project file is currently on, it will fail, understandably. Please let me know if you find any others!
We begin by gathering up all the elements we want to clean by filtering through the Element Categories and Types. Elevation Markers are the first to get collected so here we use the Categories node to select Elevations and retrieve all the project elevation markers with All Elements of Category. The Watch node is then used to check we have all the elevation markers and these are fed into a Python Script. The Python Script is used to check which of the markers are no longer hosting views and these are output. A more detailed look into the Python Script is explained in part 1.1.
The next group of elements to be collected are reference planes that are unnamed. If you’re not in the game of naming reference planes in large projects, you may not want to include this. This script assumes any reference planes that are needed, will be named. All the reference planes in the project are collected in the same manner as part 1; Categories node is used to select Reference Planes category which allows us to get all elements in this category with All Elements of Category. The Python Script in this case is used to filter all reference planes that have no name, the details of this are explained in part 2.1.
To reiterate what was said in the intro, an important thing to keep in mind when deleting views from the project is that it will fail if you try to delete the view your project is pointing at. Also, any reference plane that is hosting an element will not delete as well although that works in our favour.
Once you hit the Delete button on the windows form, all the selected elements will be deleted. If you happen to change your mind after you have deleted the elements, you can always switch over to Revit and undo the command. If you Cancel the windows form, the Python Script will basically do nothing so it can be a handy fail safe if you’ve run the script accidentally.
As always, if there is anything that didn’t quite make sense or you got stuck in following it along the way, please don’t hesitate to get in touch as I am always happy to help out. Also, if there’s anything I missed in terms of functionality, please let me know as I’m always looking to improve the scripts I work on. If you need to get in touch, you can contact me at Jeremy@LearnDynamo.com or @LearnDynamo on Twitter. Cheers and please subscribe below for the latest on upcoming modules.
April 10, 2017 @ 9:32 am
April 10, 2017 @ 10:50 am
Do the windows forms only work with Dynamo 1.3 or can I get these using Dynamo 1.2.
April 10, 2017 @ 11:02 am
No worries mate! Should work with any Dynamo version, as long as you are importing the System.Windows.Forms and System.Drawing libraries.
Weekly Roundup – 2017.15 – The BIMsider - Revit news
April 15, 2017 @ 4:22 pm
[…] Module 10 – Clean Project by Form […]
April 20, 2017 @ 12:50 pm
Thanks a lot,
I am also interested in further developments.
How fix the window form dimensions relating with the appropriate computer resolution.
May 12, 2017 @ 11:49 pm
May 5, 2017 @ 2:56 am
Found this module very helpful. Could it also include schedule views attached to assemblies? Would you be able to determine which schedule is attached to which assembly for deletion?
May 12, 2017 @ 11:55 pm
Thanks Nick. I don’t see why not, you would have to filter views and check whether it is part of any assemblies. I don’t know the methods off the top of my head but happy to help further if you are giving it a crack.