Hi I modified a dynamo node from a package called RIE nodes specifically the power nodes, node from that package. I’ve modified the node/code to first circuit element individually rather than creating one big circuit for whatever list was passed to it. I also tried integrating try & except into the code because the ElectricaSystem.create method will throw an exception if you give it a element that already has a circuit created for it. Therefore I tried adding the try& except code so I wouldn’t have to filter element before they reach the node containing the code I’ve posted to remove elements with circuits. My code works fine if I give it a list of element that are uncircuited, but if I feed it elements that are circuited revit & dynamo just instantly close upon running, can some one help me please get this code running how I’d like? Also sorry for any simple mistakes in my code I’m new to python.
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
def tolist(obj):
if isinstance(obj, list):
return UnwrapElement(obj)
else:
return [UnwrapElement(obj)]
#The inputs to this node will be stored as a list in the IN variables.
input = tolist(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
OUT=[]
for C, i in enumerate(electComponents):
TransactionManager.Instance.EnsureInTransaction(doc)
try:
b=electComponents[C]
bb=tolist(b)
newcircuit = ElectricalSystem.Create(doc, bb, ElectricalSystemType.PowerCircuit)
OUT.append(newcircuit)
except: #Exception
OUT.append(None)
continue
TransactionManager.Instance.TransactionTaskDone()