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

Previous
Next
17 responses to “Revit Macro – List electrical panel schedules and the sheets that they are placed on”
-
What would you like it to do? How about writing what sheet they are on to a project parameter on the panel itself and then creating an electrical equipment schedule that had the panel name and what sheet it shows on?
-
public void scheduling_schedules2()
{
string projectparameter = “Whatever your new project parameter is named”;//add a new instance text project parameter to the electrical equipment category.
UIDocument UiDoc = this.ActiveUIDocument;
Document Doc = UiDoc.Document;
Transaction tranny = new Transaction(Doc, “updating Panel Names”);
StringBuilder sb = new StringBuilder();
ElementCategoryFilter sheetcf = new ElementCategoryFilter(BuiltInCategory.OST_Sheets);
FilteredElementCollector sheetCollector = new FilteredElementCollector(Doc);
IList sheetlist = sheetCollector.WherePasses(sheetcf).WhereElementIsNotElementType().ToElements();ElementCategoryFilter equipcf = new ElementCategoryFilter(BuiltInCategory.OST_ElectricalEquipment);
FilteredElementCollector equipCollector = new FilteredElementCollector(Doc);
IList equiplist = equipCollector.WherePasses(equipcf).WhereElementIsNotElementType().ToElements();
tranny.Start();
foreach(Element sheet in sheetlist)
{
ElementCategoryFilter panelcf = new ElementCategoryFilter(BuiltInCategory.OST_PanelScheduleGraphics);
FilteredElementCollector panelCollector = new FilteredElementCollector(Doc, sheet.Id);
IList panellist = panelCollector.WherePasses(panelcf).WhereElementIsNotElementType().ToElements();
foreach(Element panelsched in panellist)
{
try
{
Element panel = equiplist.FirstOrDefault(p=>p.Name == panelsched.Name);//this is also assuming that all your equipment have unique names
panel.get_Parameter(projectparameter).Set(sheet.get_Parameter(BuiltInParameter.SHEET_NUMBER).AsString());//if this is for 2016, change the ‘get_Parameter’ to ‘LookupParameter’
//sb.AppendLine(panel.Name+” \t”+sheet.get_Parameter(BuiltInParameter.SHEET_NUMBER).AsString());
}
catch{}
}
}
tranny.Commit();
}-
Thank you for the code, I will try it out.
-
I’ve been trying to implement this code on Revit 2016 with no luck. The conversion to LookupParameter from get_Parameter only brought up errors. Can anyone confirm this working on Revit 2016?
-
Chris, I am finally getting the chance to dive deeper into this. Did you ever figure it out?
I know the “get_” methods were deprecated in 2016, so I believe you need to use the new method provided by the 2016 API.
-
I never did figure it out, which was disappointing. Have you had any luck? I’m not very familiar with the any of the API’s, more of a macro tinkerer. Can you help me out?
-
Hey there, I finally got around to fixing the code. I’ve tested in Revit 2016 and it is working!
-
Awesome! Where can I view it?
-
Sorry that I wasn’t more clear. I updated the code snippet in the original post. I also revised the instructions to be more descriptive. Hope this helps!
-
-
-
-
This is a great idea!
Hello,
This found this post. I tried this code but it does not work. And I am very interested with what Kidlatj ask about writing what sheet they are on.
-
Did the macro throw an error when you tried to run it?
-
Yes..But let me first say that I am a newbie with macros. But I think I followed the instructions correctly. Please see the attached image.
-
Sorry for the delayed response on this. What version of Revit are you using?
-
Hey there, I finally updated the post with the fixed code. It is working on my end in Revit 2016.
-
-
-
Hello,
I think my reply did not go thru earlier. Let me try this again. Yes but I had some error messages.
Hey, I know this is now old, but I’m using Revit 2018 to do this and it brings up the following error:
Any thoughts?
Leave a Reply