retrieve connected elements on a circuit ... advice please.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hello and thanks if anyone can take a few minutes and look at this.
What I am trying to do is retrieve all elements connected to a circuit, but the result also contains elements on other circuits. What am I doing wrong please?
public string GetCircuitElementInfo(Document doc)
{
// Filter for electrical circuits
FilteredElementCollector collector = new FilteredElementCollector(doc);
collector.OfCategory(BuiltInCategory.OST_ElectricalCircuit);
// StringBuilder to build the results string
StringBuilder messageBuilder = new StringBuilder();
messageBuilder.AppendLine("Circuit Element Information:");
// Iterate through the list of circuits
foreach (ElectricalSystem circuit in collector.OfClass(typeof(ElectricalSystem)))
{
messageBuilder.AppendLine($"Circuit ID: {circuit.Id}");
// List all elements on the circuit
foreach (Element element in circuit.Elements)
{
string elementType = element.GetType().Name;
string elementName = element.Name;
string elementId = element.Id.ToString();
messageBuilder.AppendLine($" - Type: {elementType}, Name: {elementName}, ID: {elementId}");
}
}
return messageBuilder.ToString();