Revit Macro Programming in C# and Python. Create your own Revit add-in or macros.

Revit Macro – List electrical panel schedules and the sheets that they are placed on

Revit Macro Programming in C# and Python. Create your own Revit add-in or macros.

We found a quick-and-dirty way to show what sheets your electrical panel schedules are on. Essentially, it is a schedule of schedules. We haven’t found any other way to accomplish this as of yet and we welcome any improvements to this code.

What this does is simply create a dialog box with all of your electrical panel schedules in your model and what sheets they are on. With the box open do a ctrl-c (copy to clipboard) and then paste into excel. Not very elegant but gets the job done.

For all you advanced coders out there, we could use some help in getting this to become a more elegant solution!

To create a Revit macro:

  1. Open up the macro manager and create a new C# module – name it whatever you want.
  2. With the module that you have just created selected, click the Macro button and name your macro “SchedulingSchedules”.
  3. Revit will then open “SharpDevelop”, an IDE for coding Revit macros. Look for the code block that SharpDevelop generated:
    public void SchedulingSchedules()
         {
         }
    

    and paste the code below in between the curly braces { }.

  4. Then you need to add “using System.Text;” at the top with the other using statements.
  5. Click ‘Build’ menu and then ‘Build Solution (F8)’.
  6. Switch back to Revit and you will see the “SchedulingSchedules” macro. Select the macro and click the Run button.

Code:

public void SchedulingSchedules()
         {
             UIApplication uiApp = this.Application;    
             Application app = uiApp.Application;
             UIDocument uiDoc = uiApp.ActiveUIDocument; 
             Document Doc = uiDoc.Document;
             
             StringBuilder sb = new StringBuilder(); 
             
             ElementCategoryFilter sheetcf = new ElementCategoryFilter(BuiltInCategory.OST_Sheets);
             FilteredElementCollector sheetCollector = new FilteredElementCollector(Doc); 
             IList<Element> sheetlist = sheetCollector.WherePasses(sheetcf).WhereElementIsNotElementType().ToElements(); 
         
             foreach(Element sheet in sheetlist) { 
                 ElementCategoryFilter panelcf = new ElementCategoryFilter(BuiltInCategory.OST_PanelScheduleGraphics); 
                 FilteredElementCollector panelCollector = new FilteredElementCollector(Doc, sheet.Id); 
                 IList<Element> panellist = panelCollector.WherePasses(panelcf).WhereElementIsNotElementType().ToElements(); 
                 foreach(Element panel in panellist) { 
                     sb.AppendLine(panel.Name+" \t"+sheet.get_Parameter(BuiltInParameter.SHEET_NUMBER).AsString()); 
                 } 
             }
         
             TaskDialog.Show("Revit", sb.ToString()); 
         }