Revit model management in Excel

Model management can involve some tedious tasks. Cleaning up the mess created by an unruly user when he import all categories of an old Revit model is probably the most tedious of these tasks.

When someone import elements from another model, we quickly end up with thousand of view templates, filters, and other user created views which can become totally unmanageable.

Here come the BIM Manager, who spend two tedious days sorting these views and campaigning against view proliferation.

To help address this problem, I create a small piece of code for exporting every view, template and filter to three CSV files.

To read these files in a meaningful way, I use PowerPivot in Excel to create some kind of a small database, with two relationships :

We can then create tables displaying how filters and views are used, like how many filters are used, or where the templates are applied.

Once loaded in the PowerPivot tool, this data allows us to quickly identify which template or filter are used and delete the unwanted ones.

The entire source code is available below, please feel free to use it for your own projects.

publicvoidExportViewTemplatesList(){Documentdoc=this.ActiveUIDocument.Document;//find all viewIEnumerable<View>views=fromeleminnewFilteredElementCollector(doc).OfClass(typeof(View))letview=elemasViewselectview;//Create a text file for exportingList<string>lines=newList<string>();//Add the first linelines.Add("TemplateName");foreach(Viewviewinviews){if(view.IsTemplate){lines.Add(view.Name);}}lines=lines.Distinct().ToList();stringexportpath=@"templates.csv";File.WriteAllLines(exportpath,lines.ToArray(),Encoding.UTF8);}publicvoidExportFiltersList(){Documentdoc=this.ActiveUIDocument.Document;//find all filtersIEnumerable<ParameterFilterElement>filters=fromeleminnewFilteredElementCollector(doc).OfClass(typeof(ParameterFilterElement))letfilter=elemasParameterFilterElementselectfilter;//Create a text file for exportingList<string>lines=newList<string>();//Add the first linelines.Add("FilterName");foreach(ParameterFilterElementfilterinfilters){lines.Add(filter.Name);}lines=lines.Distinct().ToList();stringexportpath=@"filters.csv";File.WriteAllLines(exportpath,lines.ToArray(),Encoding.UTF8);}publicvoidExportViewsList(){Documentdoc=this.ActiveUIDocument.Document;//find all viewIEnumerable<View>views=fromeleminnewFilteredElementCollector(doc).OfClass(typeof(View))letview=elemasViewselectview;//Create a text file for exportingList<string>lines=newList<string>();//Add the first linelines.Add("ViewName;ViewType;IsTemplate;"+"TemplateName;LevelName;FilterName");foreach(Viewvinviews){Levellevel=v.GenLevel;stringlevelName="";if(level!=null){levelName=level.Name;}//Get view filtersICollection<ElementId>filterIds;try{filterIds=v.GetFilters();}catch(Autodesk.Revit.Exceptions.InvalidOperationException){filterIds=newList<ElementId>();}stringtemplateName="";if(v.ViewTemplateId.IntegerValue!=-1){templateName=doc.GetElement(v.ViewTemplateId).Name;}stringviewinfos=v.ViewName+";"+v.ViewType+";"+v.IsTemplate.ToString()+";"+templateName+";"+levelName;if(filterIds.Count!=0){foreach(ElementIdfilterIdinfilterIds){stringfilterName=doc.GetElement(filterId).Name;stringline=viewinfos+";"+filterName;lines.Add(line);}}else{lines.Add(viewinfos);}}stringexportpath=@"views.csv";File.WriteAllLines(exportpath,lines.ToArray(),Encoding.UTF8);}