Aha, I was working with the Create method for an unused connector. That makes sense.
Alot of my imports are probably not needed. I am just starting to learn python in Dynamo.
I still cannot make it though. I do not get what to input for “ElectricalSystemType”
import clr
clr.AddReference('ProtoGeometry')
from Autodesk.DesignScript.Geometry import *
clr.AddReference('RevitServices')
import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager
from System.Collections.Generic import *
clr.AddReference('RevitNodes')
import Revit
clr.ImportExtensions(Revit.Elements)
clr.AddReference('RevitAPI')
import Autodesk
from Autodesk.Revit.DB import *
clr.AddReference('DSCoreNodes')
import DSCore
from DSCore.List import *
import sys
pyt_path = r'C:\Program Files (x86)\IronPython 2.7\Lib'
sys.path.append(pyt_path)
#The inputs to this node will be stored as a list in the IN variables.
input = UnwrapElement(IN[0])
addto = UnwrapElement(IN[1])
doc = DocumentManager.Instance.CurrentDBDocument
uiapp = DocumentManager.Instance.CurrentUIApplication
app = uiapp.Application
uidoc = DocumentManager.Instance.CurrentUIApplication.ActiveUIDocument
OUT = []
elemSet = ElementSet()
for _ in input:
elemSet.Insert(_)
OUT = input, addto
TransactionManager.Instance.EnsureInTransaction(doc)
Autodesk.Revit.DB.Electrical.ElectricalSystem.Create(doc, elemSet)
TransactionManager.Instance.TransactionTaskDone()
They are called Enumerations and are constant variables (immutable/not changeable), if you want to use a string input to choose from you can use the Enum.Parse() method. See an example here.
import clr
clr.AddReference('ProtoGeometry')
from Autodesk.DesignScript.Geometry import *
clr.AddReference('RevitServices')
import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager
from System.Collections.Generic import *
clr.AddReference('RevitNodes')
import Revit
clr.ImportExtensions(Revit.Elements)
clr.AddReference('RevitAPI')
import Autodesk
from Autodesk.Revit.DB import *
from Autodesk.Revit.DB.Electrical import *
from Autodesk.Revit.DB import MEPSystem
clr.AddReference('DSCoreNodes')
import DSCore
from DSCore.List import *
import sys
pyt_path = r'C:\Program Files (x86)\IronPython 2.7\Lib'
sys.path.append(pyt_path)
# Import List ( ICollection(ElementId) = List[ElementId]() )
clr.AddReference("System")
from System.Collections.Generic import List
#The inputs to this node will be stored as a list in the IN variables.
input = UnwrapElement(IN[0])
electComponents = List[ElementId]()
for i in input:
electComponents.Add(i.Id)
doc = DocumentManager.Instance.CurrentDBDocument
uiapp = DocumentManager.Instance.CurrentUIApplication
app = uiapp.Application
uidoc = DocumentManager.Instance.CurrentUIApplication.ActiveUIDocument
TransactionManager.Instance.EnsureInTransaction(doc)
ElectricalSystem.Create(doc, electComponents, ElectricalSystemType.PowerUnBalanced)
TransactionManager.Instance.TransactionTaskDone()
OUT = []
Does anyone know what I need to input that can create the specific circuit “ElectricalSystemType.PowerUnBalanced” ?
From what I can guess from the error message: the input elements don’t have a PowerUnbalanced connector assigned in their family. You could check this by editing the family.
Thanks. I checked the family, and the electrical connector is of type Power Balanced, so I changed the code to “ElectricalSystemType.PowerBalanced”, but still got the same error message.
Turns out that one of the elements I input was already connected to a circuit, which caused the error.
Setting the ElectricalSystemType to PowerCircuit did the trick.
HI,
I was trying to do the same, and I found your code but I get the same error.
The “.create” seems to be unsupported in the electrical system class. Any help on how to solve this will be much appreciated
Great
It also seems that the script does not run well if already powered elements are part of the selection.
I think that could be implemented in the script with a boolean input; Disconnect powered elements and connect the input elements all together, or to skip already powered elements and connect the remaining elements to a new circuit.
By the way I have published a few nodes in a package called “RIE”. Nodes for creating circuits, selecting panel, and drawing wires for circuit ++.
The code for the nodes is implemented for revit 2018, so some of them might not work on older versions.
Do you know of any good packages for electrical installations?
I have MEPover, which has been kind of useful, but I still haven’t found any great packages for creating stuff for electrical installations.
Thanks alot
MEP over is the best one.
But for electrical systems I use a combination of shared parameters and excel sheets to perform necessary calculations
I’m new to Python and after several failed attempts; unable to adapt the code for 2017. Is there a chance you could provide your fix for the 2017 versions?
Does anyone know if its possible to modify the above python code, so that it generates a circuit per fittings selected.
i’m looking into doing something with modular wiring. This could work well if it could create a new circuit per fitting and connect to a control module, That then connects to a DB.