ICollections

revit
python

#1

Hello ,

when im try use next method : (try create ICollections)

clr.AddReference("System")
from System.Collections.Generic import List
Ids=List[ElementId]()
for i in IN[0]:
	Ids.Add(UnwrapElement(i).Id)

have a next trouble : ElementId is not found
In IN[0] im give pipe insulations or any another elements from revit

whats the problem?


#2

Solution:
Shoud be import Revit API for detect ElementId

import clr

clr.AddReference('RevitAPI')
from Autodesk.Revit.DB import * #use ElementId
from System.Collections.Generic import * #use LIST

if isinstance(IN[0],list):
	els = UnwrapElement(IN[0])
else:
	els = [UnwrapElement(IN[0])]
	
lst_id = []
lst =[]
for i in UnwrapElement(els):
	lst_id.append(i.Id)
icolls = List[ElementId](lst_id)

OUT = icolls

#3

you dont need to unwrap so many times…

import clr
clr.AddReference('RevitAPI')
from Autodesk.Revit.DB import ElementId
from System.Collections.Generic import List

elements = IN[0]
if not isinstance(elements, list):
    elements = [elements]

ids = []
for element in UnwrapElement(elements):
	ids.append(element.Id)

OUT = List[ElementId](ids)

#4

@erfajo thanks to show me this shortest and easy way)