RIE_PowerElements for CPython3

I’m attempting to use the RIE package in Dynamo to take in uncircuited receptacles and create a circuit for them. From what I’ve been able to research, RIE has a built in function called PowerElements, but when I feed my list of receptacles into that function there is no output (or any warnings/errors thrown). The code is below:

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.PowerCircuit)

TransactionManager.Instance.TransactionTaskDone()

OUT = []

I believe the issue comes from the lines:

import sys
pyt_path = r'C:\Program Files (x86)\IronPython 2.7\Lib'
sys.path.append(pyt_path)

All the python scripts I’m running in dynamo use CPython3 since IronPython 2.7 doesn’t work. I’m unable to find a directory for CPython3 or how to modify this code segment.

Can someone assist with this? Much appreciated.

in your code an empty list is assigned to the variable OUT

try this instead

TransactionManager.Instance.EnsureInTransaction(doc)

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

TransactionManager.Instance.TransactionTaskDone()

OUT = elecSystem

you can delete lines if you use CPython3 engine

Thanks for pointing these out!

I updated the code segments as described but the code block is still giving null as an output (I also commented out the pyt_path lines)

as reference the code now looks like:

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)

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

TransactionManager.Instance.TransactionTaskDone()

OUT = elecSystem

any other ideas on how to get an output? Thanks so much again!

  • Is your equipment already connected to a circuit?
  • Are the electrical parameters of the equipment correct?

you can also try to create a circuit from the electrical connectors