How to get Elements that can be value of parameter(StorageType = ElementId)?

How to get Elements that can be value of parameter(StorageType = ElementId)?

qoreodlf37
Enthusiast Enthusiast
140 Views
1 Reply
Message 1 of 2

How to get Elements that can be value of parameter(StorageType = ElementId)?

qoreodlf37
Enthusiast
Enthusiast

Hi, I want to get elements list that can be value of parameter(StorageType = ElementId).
I used this code.

Element ele = Doc.GetElement(param.AsElementId());
List<ElementId> ids = new FilteredElementCollector(Doc).OfCategory((BuiltInCategory)ele.Category.Id).Select(x => x.Id).ToList();

It works well. But it can't when  param.AsElementId = -1.

 

So I want to know the way when param.AsElementId = -1.

0 Likes
141 Views
1 Reply
Reply (1)
Message 2 of 2

jeremy_tammik
Alumni
Alumni

An element id of -1 refers to an invalid or non-existent element. So, it cannot be retrieved. You will need to handle that case differently. Please refer to the documentation of the InvalidElementId property:

  

https://www.revitapidocs.com/2024/08ae8886-6ab3-3ef5-d2e0-0da2ffa7bd2c.htm

  

Jeremy Tammik Developer Advocacy and Support + The Building Coder + Autodesk Developer Network + ADN Open
0 Likes