Python; Create new circuit in panel and assign electrical elements to circuit

mep
python

#1

So far I am able to reassign electrical elements to an existing circuit.

I want to be able to create a new Electrical System (Circuit) connected to a provided Panel element.

Any clues how to do that?

Here is what I have so far:

Thanks to @Mostafa_El_Ayoubi for helping me figure out how to reassign elements to existing circuits.


#2

@andre.abotnes please copy pase your code.

Basically you need to create the ElectricalSystem defining all the arguments of the Constructor (you’re missing the document) :
image

Then add your ElementSet to this electrical system .


#3

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” :blush:

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()


#4

Hei André! Just write ElectricalSystemType.x and replace the x with one of the following types.

image

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.


#5

Thank you so much for your help!

I am currently getting this error message:

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” ?


#6

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.


#7

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.

I am able to manually connect the lighting fixture to power.


#8

Try setting it to PowerCircuit, that worked for me.


#9

Damn I still get the errormessage.


#10

Can you send me the graph and the family you connect, which works for you?


#11

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.

Thanks to @Einar_Raknes, @T_Pover & @Mostafa_El_Ayoubi

circuitstest.dyn (22.8 KB)


#12

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


#13

This method was introduced in 2018, it will not work in Revit 2017


#14

For older version you can use this method: doc.Create.NewElectricalSystem() with all the same arguments as the newer version.


#15

Thanks alot
This solved the problem


#16

Great :slight_smile:
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.


#17

Thanks alot :smile:
MEP over is the best one.
But for electrical systems I use a combination of shared parameters and excel sheets to perform necessary calculations


#18

Hey Editor_X

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?

Thanks!!

Edit: Feel stupid, see below

change:

newcircuit = doc.Create.NewElectricalSystem.NewElectricalSystem(c,ElectricalSystemType.PowerCircuit)

to

newcircuit = ElectricalSystem.Create(doc, electComponents, ElectricalSystemType.PowerCircuit)