Creating an electrical circuit to electrical elements

This query is an extension to a previous post on assigning elements to a circuit.

The file posted circuitstest.dyn is a great solution to creating a wire circuit between elements.

However, I don’t have the required skills to alter the python code, but I would like to ask whether this code could be altered to accept the passing of a list of elements. I found it fell over with the follow message, when I tried passing a list. It works well when manually selecting elements, but I was hoping to do the same with a list. I suspect this may also require alterations to the python code further downstream.


The graph is largely unchanged, I added a list of elements to process and got the following error below.

Any help here will be much appreciated.

Would you be able to post the code contained in the first node? Your error implies that the code expects a single element rather than a list of elements, so a for loop should be used. For example, the code may have a line such as:

element.Id

However you will have to add a loop like this:

for element in elements:
    element.Id
    # additional code

Thanks @cgartland for your reply, I’m not sure on the method in posting code, never posted it before, so apologies if it’s in the wrong format.

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

circuit = UnwrapElement(IN[0])

panel = UnwrapElement(IN[1])

doc = DocumentManager.Instance.CurrentDBDocument

uiapp = DocumentManager.Instance.CurrentUIApplication

app = uiapp.Application

uidoc = DocumentManager.Instance.CurrentUIApplication.ActiveUIDocument

TransactionManager.Instance.EnsureInTransaction(doc)

for _ in circuit:

_.SelectPanel(panel)

TransactionManager.Instance.TransactionTaskDone()

#Assign your output to the OUT variable.

OUT =

OUT = circuit, panel

Mark your code text in the reply and click this button

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

circuit = UnwrapElement(IN[0])

panel = UnwrapElement(IN[1])

doc = DocumentManager.Instance.CurrentDBDocument

uiapp = DocumentManager.Instance.CurrentUIApplication

app = uiapp.Application

uidoc = DocumentManager.Instance.CurrentUIApplication.ActiveUIDocument

TransactionManager.Instance.EnsureInTransaction(doc)

for _ in circuit:

_.SelectPanel(panel)

TransactionManager.Instance.TransactionTaskDone()

#Assign your output to the OUT variable.

OUT = 

OUT = circuit, panel

Thanks Andre

Maybe this helps?

If any of the elements with which you are trying to create a circuit already has one, I believe you will get an error, so I recommend removing existing power manually before running the script.

1 Like

Hello Andre,

We had legend racing driver who tore up multiple circuits, he was called “Peter Perfect”

I now anoint you “Andre Seamless” as your solution now seamlessly pulls together all those circuits in a slick racing machine.

1 Like

lol
Glad to hear you got it to work :slight_smile:

sir could you please help me
how can I assign spare in electrical panel schedule by dynamo
thank you in advance ?