Electrical Circuiting Python

Hi,

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(‘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) = ListElementId )

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 = ListElementId

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)

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

OUT =
OUT.append(newcircuit)

TransactionManager.Instance.TransactionTaskDone()

Hi,

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.

Edit: heres a good thread for this.

3 Likes

Ah, frustrating.

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.

1 Like

yeah, the API is a pain. Like I said, i had to rewrite the RIE package to use to old API. its not too much of a change.

Good luck, let me know if you need help.

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:

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

with this:

doc.Create.NewElectricalSystem(electComponents, ElectricalSystemType.PowerCircuit)

Refer to this documentation, where the version history is marked in the top left corner:
ElectricalSystem.Create:
http://www.revitapidocs.com/2018/66f12d78-a4ab-9b99-ef49-92c3a3e1835e.htm
doc.Create.NewElectricalSystem:
http://www.revitapidocs.com/2018/76133688-ad7c-6e66-84df-d1122a6a0e6e.htm

1 Like

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.

1 Like

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.

Hi Dan,

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.

Andre.

1 Like

Hi I was actually able to get it to work with the script in Joe.Ashton’s image. I think I was just making newbie mistakes.

Thanks for the response

2 Likes

Hi Dan,

if you solve the issue let me know too.