Message 1 of 7
Specify the voltage when creating an electrical system
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hi, I'm trying to create an electrical circuit. I am trying to use the method ElectricalSystem.Create(Document, IList(ElementId), ElectricalSystemType) - https://www.revitapidocs.com/2021.1/66f12d78-a4ab-9b99-ef49-92c3a3e1835e.htm . But after the creation, the electric circuit has a voltage of 0. Can I specify the voltage level when creating an electric system.
using Autodesk.Revit.Attributes;
using Autodesk.Revit.DB;
using Autodesk.Revit.DB.Electrical;
using Autodesk.Revit.UI;
using Autodesk.Revit.UI.Selection;
using System.Collections.Generic;
using System.Linq;
namespace RevitPlugins
{
[Regeneration(RegenerationOption.Manual)]
[Transaction(TransactionMode.Manual)]
public class Class : IExternalCommand
{
public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
{
UIDocument uidoc = commandData.Application.ActiveUIDocument;
Document doc = uidoc.Document;
Selection sel = uidoc.Selection;
Reference reference = sel.PickObject(ObjectType.Element);
FamilyInstance familyInstance = (doc.GetElement(reference) as FamilyInstance);
ElectricalSystem system = familyInstance.MEPModel.GetElectricalSystems().FirstOrDefault();
IList<ElementId> familyInstances = new List<ElementId>();
ElementSet list_element = system.Elements;
foreach (FamilyInstance family in list_element)
{
familyInstances.Add(family.Id);
}
ElectricalSystemType electricalSystemType = ElectricalSystemType.PowerCircuit;
using (Transaction tr = new Transaction(doc, "Voltage change"))
{
tr.Start();
doc.Delete(system.Id);
ElectricalSystem electricalSystem = ElectricalSystem.Create(doc, familyInstances, electricalSystemType);
tr.Commit();
}
return Result.Succeeded;
}
}
}
Sample code: