List[Element] has no attribute Concat

I have a python node where I’m using 2 FilteredElementCollectors to filter my initial Revit selection. One for Cable Tray one for Cable Tray Fittings. I realized after I made these that I actually want to output two different lists - one with just the cable tray, one with cable tray & cable tray fittings.

I could make a ElementMulticategoryFilter and all that, but I figure I already had the two written out, it should be simple enough to just combine the two, but I seem to be having trouble making that work.

Here’s the code:

# Enable Python support and load DesignScript library
import clr

# Import RevitAPI - This gives general access to Revit tools.
clr.AddReference("RevitAPI")
import Autodesk
from Autodesk.Revit.DB import BuiltInCategory as bic, Element, ElementId, FilteredElementCollector

# The System namespace at the root of .NET
import System 
from System.Collections.Generic import List

# Import DocumentManager & TransactionManager
clr.AddReference("RevitServices")
import RevitServices
from RevitServices.Persistence import DocumentManager

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


# The inputs to this node will be stored as a list in the IN variables.
dataEnteringNode = IN

# Start Code

sel = uidoc.Selection.GetElementIds()

ct = FilteredElementCollector(doc, sel).OfCategory(bic.OST_CableTray).ToElements()
ctf = FilteredElementCollector(doc, sel).OfCategory(bic.OST_CableTrayFitting).ToElements()

# Assign output
OUT = ct, ct.Concat(ctf)

I get the error mentioned in the title when I try to run this. I also tried ct.Union(ctf) but no luck there either. Am I missing something in the imports, or does IronPython not support these methods or some such?

Concatenation is typically for strings and similar objects, not for lists. To add to lists you can use append or extend. These do not create new lists however, so you will have to do that manually.

EDIT: Sorry, extend, not add.

Ah, yeah, that’s a good point. However those are python list methods, right? FilteredElementCollectors outputs an IList. I know I can use list.Add, but that’s to add individual elements to a list. I could make a for loop, but ultimately I’m still curious why I can’t seem to combine two iLists in IronPython.

In order to maintain list structure I think you have to add individual elements anyway. Manually appending the two lists would be the easiest way otherwise (newList = [list1,list2]).

In this instance I don’t necessarily care about the list structure. [list1,list2] is the obvious solution I was overlooking, thanks!

If anyone else is curious I did finally mange to track down the C# answer -

ctf.AddRange(ct)
OUT = ct, ctf

will also achieve what I was looking for.

2 Likes

Someone else can probably give a more complete answer, but iLists are an interface for a collection, not just a List of elements. iLists don’t have access to all the same methods and have to be modified in a different way.

Concat() is a Linq extension method, if you want to use it, it is necessary to add the System.Linq extension

Note
unfortunately, this extension is not available with CPython3/Python.Net engine

[EDIT]
Eventually I found it was possible with PythonNet using System.Linq static methods

2 Likes