this were my code
using Autodesk.Revit.Attributes;
using Autodesk.Revit.DB;
using Autodesk.Revit.UI;
using System;
using System.Collections.Generic;
using System.Linq;
[Transaction(TransactionMode.Manual)]
public class GetAllElectricalCircuitsCommand : IExternalCommand
{
public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
{
// Get the Revit document
Document doc = commandData.Application.ActiveUIDocument.Document;
try
{
// Get the active view
View activeView = doc.ActiveView;
// Filter electrical circuits visible in the active view
IList<Element> electricalCircuits = new FilteredElementCollector(doc, activeView.Id)
.OfCategory(BuiltInCategory.OST_ElectricalCircuit)
.WhereElementIsNotElementType()
.ToList();
// Create a list to store the information for each electrical circuit
List<string> circuitInfo = new List<string>();
// Append the name and ID of each electrical circuit, along with the name of the active view
foreach (var circuit in electricalCircuits)
{
circuitInfo.Add("ID: " + circuit.Id.IntegerValue + ", Name: " + circuit.Name + " - Active View: " + circuit.Document.ActiveView.Name);
}
// Display the count of electrical circuits and their information using TaskDialog
TaskDialog taskDialog = new TaskDialog("Electrical Circuits");
taskDialog.MainContent = "Total Electrical Circuits in " + activeView.Name + " view: " + electricalCircuits.Count + "\n\n";
taskDialog.MainContent += string.Join("\n", circuitInfo);
taskDialog.Show();
return Result.Succeeded;
}
catch (Exception ex)
{
TaskDialog.Show("Error", ex.Message);
return Result.Failed;
}
}
}
this were my code . The project i was testing on is actually the Snowdon tower Sample project in Revit 2024

what i found interesting is ActiveView of all OST_ElectricalCircuit will automatically change to the level which is oppening. That's why it display all the circuit. in the code i was acctually display all the active view of all circuit, even they are at different level but they only show the current level. I think this is error because Active view work fine with other but not the circuit. Thank you