How to select a single element in Revit? C#

How to select a single element in Revit? C#

rita.aguiar
Advocate Advocate
11,517 Views
6 Replies
Message 1 of 7

How to select a single element in Revit? C#

rita.aguiar
Advocate
Advocate

I have tried with:

 

uidoc.Selection.SetElementIds(elementid);

SetElementIds requires an ICollector<ElementId> as argument and so I don't know how to only select a single element through its id, of type ElementId.

 

Any help would be appretiated.

 

 

0 Likes
Accepted solutions (1)
11,518 Views
6 Replies
Replies (6)
Message 2 of 7

jeremytammik
Autodesk
Autodesk
Accepted solution

Create a new, empty, list of element ids, i.e., an `IList<ElementId>`, add your one single element to that, and pass it in as an argument to SetElementIds.

 



Jeremy Tammik
Developer Technical Services
Autodesk Developer Network, ADN Open
The Building Coder

Message 3 of 7

so-chong
Advocate
Advocate

Hi,

Did you try to use the PickObject Method to select one object?

Something like this

 

ElementId elementid = null;

elementid = uidoc.Selection.PickObject(ObjectType.Element, "Select element or ESC to reset the view").ElementId;
Message 4 of 7

NinovSM
Advocate
Advocate

Hello, do you know similar method for highligthing like SetElementIds but for subelements?

0 Likes
Message 5 of 7

jeremy_tammik
Alumni
Alumni

Nope, sorry, I do not believe this exists.

 

You could submit a wish list item for this in the Revit Idea Station.

 

You could also try to highlight something using AVF or direct context 3D, cf.,

  

https://thebuildingcoder.typepad.com/blog/2020/10/onbox-directcontext-jig-and-no-cdn.html#3

  

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

Walker.Jack
Observer
Observer

Does the SetElements retrieve the elements from the database and highlight them in the UI or does it simply retrieve the elements from the database?

0 Likes
Message 7 of 7

jeremy_tammik
Alumni
Alumni

It does not retrieve elements from the database.

  

It does select and highlight them in the UI.

 

For an example, please refer to the official Revit SDK and the SDK sample DirectionCalculation / FindSouthFacingWalls.

  

  

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