简体   繁体   中英

Create a collection of item ids Revit API in Python

So I am trying to use a list of input strings to isolate them in a view using Revit API. I got this far, but I am getting stuck where I am trying to create a set that takes all elements in a view and removes ones that are created from input IDs. I am doing this to end up with a set of all elements except ones that i want to isolate.

dataEnteringNode = IN0
view = IN0
str_ids = IN1
doc = __doc__
collector = FilteredElementCollector(doc, view.Id)

for i in str_ids:
    int_id = int(i)
    id = ElementId(int_id)
    element = doc.GetElement(id)
    element_set = ElementSet()
    element_set.Insert(element)

elements_to_hide = collector.WhereElementIsNotElementType().Excluding(element_set).ToElements()

#Assign your output to the OUT variable
OUT = elements_to_hide

I would greatly appreciate a help in solving this error. I am getting that "expected ICollection[ElementId], got set". I am guessing the problem lies in a Excluding filter where i need to create a collection of Ids to exclude but I dont know how. Thank you in advance. Thank you for help in advance!

The reason your code doesn't work is that ElementSet in the Revit API does not implement the ICollection<T> interface - just the IEnumerable<T> . So, to get your code working, you will need to create an ICollection<T> object from your set.

Try something like this:

# ...
from System.Collections.Generic import List
element_collection = List[ElementId](element_set)
elements_to_hide = collector.WhereElementIsNotElementType().Excluding(element_collection).ToElements()

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM