I’ve been tasked with starting a electrical circuiting script.
Now i’ve had a number of issues getting this running due to powering electrical elements.
However, I came across this python script in an old post that can power a list of elements (which is great)
My problem is that when I want to add multiple (to add more automation) It doesnt power per seperate list, so I was basically wondering if its something in the code that would allow me to update that? My Python knowledge is very limited, so that’s why this has stumped me.
Likewise if anyone has any links to any good posts about circuiting, or anything related that I might have missed, that would be appreciated.
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(‘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 *
Trying using the RIE package, it has lots of nodes for circuiting.
I had a similar script and I created circuits based on a panel then adds components after.
I know that the API has changed a bit depending on what version you are in. The one I made is for 2016, the RIE I believe is either 2017 or 2018 and newer.
I used the RIE previously and couldn’t get it to work, wouldn’t power the elements no matter how I brought it in. Testing it just now again after that and it works straight away, might have been a Revit API version issue as I use Revit 2016-2018, i’ll double check that issue.
As for the second link you sent, yes, that’s where I got the other information from.
Thanks though, i’ll definitely check out the RIE package a bit more in depth.
Your python script is made for a single list input. That means it is made for creating only one circuit from a single list of input elements.
To solve it, it might work to put the python script in a list.map node, or changing the python script to loop through each sublist.
I believe this change to your python script would help for the input your giving your node.
OUT = []
for each sublst in input:
electComponents = ListElementId
for each item in sublst:
electComponents.Add(item.Id)
doc = DocumentManager.Instance.CurrentDBDocument
uiapp = DocumentManager.Instance.CurrentUIApplication
app = uiapp.Application
uidoc = DocumentManager.Instance.CurrentUIApplication.ActiveUIDocument
TransactionManager.Instance.EnsureInTransaction(doc)
newcircuit = ElectricalSystem.Create(doc, electComponents, ElectricalSystemType.PowerCircuit)
OUT.append(newcircuit)
TransactionManager.Instance.TransactionTaskDone()
On a side note:
If you are running on an older version than Revit 2018, you might want to try switching out this:
Hi Vykr,
the Revit api documents say that the ElectricalSystem.Create() function was added-, and that the doc.Create.NewElectricalSystem() was deemed obsolete in Revit 2018.
Hi Andre,
I have a little experience with python, but very little with python for dynamo.
I’m also trying to get this python script to create multiple circuits with multiple sublists of elements rather than a single list input.
Unfortunately the python script you posted has not helped. I will keep tryuing different ideas but I feel like you are very close to getting it to work. I can get it to work with a single input but I can’t think of any clever ways to get it to create mutliple circuits other than getting it to go through sublists.
Any clue what might be wrong with the code you posted or another work around to getting it to take in a sublist of elements?
Thank you so much! I’ll keep trying different stuff and report back if I find a solution.
I’m sorry it did not work, an easy solution might be to use the code that is working for creating a single circuit from a list of elements, and making it into a node. Then you can set levels to level 2, and input multiple lists of elements, and get multiple circuits out. Hope this helps.