A recent post at whatrevitwants mentions some tools that can be used to find in-place families. Here is a tiny macro to do the same
public void findInPlaceFamilies()
{
string info = "";
Document doc = this.ActiveUIDocument.Document;
foreach (Family family in new FilteredElementCollector(doc).OfClass(typeof(Family)).Cast<Family>())
{
if (family.IsInPlace)
info += family.Name + "\n";
}
TaskDialog.Show("In Place Families", info);
}
This is also a good excuse to show how to do something other than show the string inside Revit in a TaskDialog. For example, we might want to write the data to a text file or to an Excel file.
Text File:
public void findInPlaceFamilies()
{
Document doc = this.ActiveUIDocument.Document;
// Use the @ before the filename to avoid errors related to the \ character
// Alternative is to use \\ instead of \
string filename = @"C:\Users\HP002\Documents\In Place Families.txt";
// Create a StreamWriter object to write to a file
using (System.IO.StreamWriter writer = new System.IO.StreamWriter(filename))
{
foreach (Family family in new FilteredElementCollector(doc).OfClass(typeof(Family)).Cast<Family>())
{
if (family.IsInPlace)
writer.WriteLine(family.Name);
}
}
// open the text file
System.Diagnostics.Process.Start(filename);
}
Excel File:
- Select “Project – Add Reference” from the SharpDevelop menu bar and add a reference to Microsoft.Office.Interop.Excel

- Add these lines to the other “using” statements at the top of your file:
using Microsoft.Office.Interop.Excel;
using System.Reflection;
- Adding “Microsoft.Office.Interop.Excel” may result in errors like this if elsewhere in your macros you are using the Revit Parameter class:

This happens because now you can no longer define variables as “Parameter” because both Autodesk.Revit.DB and Microsoft.Office.Interop.Excel contain definitions for “Parameter”. The compiler can’t guess which one you want to use.
Go through these errors and replace “Parameter” with “Autodesk.Revit.DB.Parameter” like this:
Autodesk.Revit.DB.Parameter parameter = element.get_Parameter("Material");
public void findInPlaceFamilies()
{
Document doc = this.ActiveUIDocument.Document;
// set up Excel variables
Application excelApp = new Application();
Workbook workbook = excelApp.Workbooks.Add(Missing.Value);
Worksheet worksheet = (Worksheet)workbook.ActiveSheet;
string filename = @"C:\Users\HP002\Documents\In Place Families.xls";
int rowCtr = 1;
foreach (Family family in new FilteredElementCollector(doc).OfClass(typeof(Family)).Cast<Family>())
{
if (family.IsInPlace)
{
// write data to the next row in the spreadsheet
worksheet.Cells[rowCtr,1] = family.Name;
rowCtr++; // increment counter by one
}
}
// Save the file
workbook.SaveAs(filename,XlFileFormat.xlWorkbookNormal,
Missing.Value, Missing.Value, Missing.Value, Missing.Value,
XlSaveAsAccessMode.xlExclusive, Missing.Value, Missing.Value, Missing.Value,
Missing.Value, Missing.Value);
// Clean up the excel resources that were created
workbook.Close();
excelApp.Quit();
System.Diagnostics.Process.Start(filename);
}
Don’t mind all that crazy “Missing.Value” stuff. The Excel API is strange but it works.
Like this:
Like Loading...