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 ?

@andre.abotnes
Uhm…RIE_SelectPanel works, but the circuits have no name (1,2,3…) and if we try to “get item” or “get parameter name” of these circuit we see “no name”.
This is a problem because we need to see numbers!

Hi there @Simo92
I am sorry to hear about this issue, and I am not familiar with it.
Could you send an image showing this erroneous data both in Dynamo and Revit?
I have not updated my nodes alot the past 2 years, so there may have been some changes to the API I should adjust to for newer versions of Revit.
What versions of Revit and Dynamo are you experiencing this issue on?
I will have to look into this, but at the moment I am on paternity leave, so I cannot say exactly when I will find the time to update my package.

Thanks for the headsup, hope to hear from you soon.

Regards
André

Hi @andre.abotnes
Thanks for your answer, I am an electrical designer who works every day in the BIM field and I have a good knowledge of Revit and a medium knowledge of Dynamo.
Lately I have been working with the parameterization of electrical circuits and the RIE and MEPover packages are really useful, which are the only ones I know that can offer what I am looking for:
- Creation of the automatic circuit
- Moving the lines of the circuit
At the time of using Revit 2022 and I encountered the following problem:
the automatic creation of the circuits from the RIE package does not name the circuits (1,2,3, …) and consequently I cannot then “find” them with other nodes to extract the internal parameters.
I’m italian, I hope that you can understand me and my upload image.
First node choose elements and the second choose panel in the same way you explain.
Circuiti is created with successful in schedule panel but have no name.
I created a parameter called “fattore contemporaneità” inside “circuit category” but for change this or other parameter i need the number of circuit (the name).
With a normal circuit created with Revit (without dynamo) i success have tha name of circuit and then i can change parameters, so i think that the problem is really the “no name circuit” when i use RIE automatic circuit.
I’m sorry for grammar error.
I am very grateful for your work and I hope to have your answer.
Thank you

It seems to me that the panel never gets selected for the given circuit.
Is the element you’re inputing a valid power panel? Can you select this element as panel manually?
I believe one thing you could try is to create a Code Block in front of the Panel input and just insert this inside of it:
[panel]
and then couple it in between your select model element node and the selectpanel node, making the input a list of 1 element instead of just 1 element.
I believe that the Select Panel node is coded in such a way that it expects a list of elements and not single elements as input (I cannot recall for sure that this is the issue).
Hope that was an understandable approach.

Hi @andre.abotnes
Unfortunately this solution doesn’t work. I add he code node like you suggest but remain “empty name” on name circuit.
I try to add my elements manually with Revit and the result is that circuit have name (in this case one only circuit and the name is the same for the two elements: “1”).
So i think that the problem are not my elements because i used them always in my work.
Only when i use this automatic package i lose the name of circuit.
However i obtain the circuit in panel schedule, only lose the name.
But the name is the only “bridge” that permit me to link elements with


panel, and this is a bad lost for an electrician!
I’m so sad beacuse i like really an automatic package like RIE Select Panel in my work.

So sorry to hear that it doesn’t work! In that case I will have to look into it when I am able to access my files again. I will get back to you as soon as I can :slight_smile: In the meantime, best of luck!

Hi @r.lietz
Is it possible to share your final script for the electrical circuit?

Thanks in advance.