Revit Python_Add Value In Comment Parameter Of Electrical Circuit

Dear All,

I am new in python and trying to create python script for task as below.

Get ‘Panel’ parameter value from electrical circuit & based on that value I want to add value in comments parameter. For example if Panel name start with EDB then comment parameter value shall be Emergency & If Panel name start with UDB then comment parameter value shall be UPS.

When I run python script which I have created, It is adding Emergency value in comments parameter even if panel name start with UDB.

Kindly advice.
Set PC_System Type For Electrical Circuits_Python.dyn (4.9 KB)

Can you paste the python code here (as preformatted text) so we can see it, along with a screenshot of the input(s) and output(s) you have?
image

Hello @Nick_Boyts ,

import clr

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

import System
from System.Collections.Generic import *

clr.AddReference('ProtoGeometry')
from Autodesk.DesignScript.Geometry import *

clr.AddReference("RevitNodes")
import Revit
clr.ImportExtensions(Revit.Elements)
clr.ImportExtensions(Revit.GeometryConversion)
clr.AddReference("RevitServices")
import RevitServices
from RevitServices.Persistence import DocumentManager 
from RevitServices.Transactions import TransactionManager 

clr.AddReference("RevitAPI")
clr.AddReference("RevitAPIUI")

import Autodesk 
from Autodesk.Revit.DB import *
from Autodesk.Revit.DB.Electrical import *
from Autodesk.Revit.UI import *

doc = DocumentManager.Instance.CurrentDBDocument
uiapp = DocumentManager.Instance.CurrentUIApplication 
app = uiapp.Application 
uidoc = uiapp.ActiveUIDocument

def tolist(obj1):
	if hasattr(obj1,"__iter__"): return obj1
	else: return [obj1]

#Preparing input from dynamo to revit
element = UnwrapElement(IN[0])

#Do some action in a Transaction

TransactionManager.Instance.EnsureInTransaction(doc)


#001 - Create a filtered element collector to retrieve all electrical circuits
collector = FilteredElementCollector(doc).OfCategory(BuiltInCategory.OST_ElectricalCircuit)


#002 - Create a list to store the filtered circuits
filtered_circuits = []


for circuit in collector:
	panel_param = circuit.LookupParameter("Panel").AsString()
	if panel_param.startswith("EDB-"):
		filtered_circuits.append(circuit)
		for circuit in filtered_circuits:
			comments_param = circuit.LookupParameter("Comments")
			comments_param.Set("Emergency")
	elif panel_param.startswith("UDB-"):
		filtered_circuits.append(circuit)
		for circuit in filtered_circuits:
			comments_param = circuit.LookupParameter("Comments")
			comments_param.Set("UPS")


		
TransactionManager.Instance.TransactionTaskDone()

OUT = filtered_circuits

Thank you.

The problem is your second group of for loops. You step through each circuit in the collector and add it to the new list but then step through all of the circuits in the new list and update their comment value. This is overwriting every circuit, every loop.

You just need to remove the second set of for loops altogether. You want to write to the parameter of the active circuit in the loop as you’re handling it.

Hello @Nick_Boyts

I updated script as you suggested & It works as expected.

Thank for your response