Is there a method Revit API where I can select elements in order, highlighting the elements selection.
Please note, Selection.PickObjects() does the selection & highlighting but does not save the elements in the order of Selection.
Is there a method Revit API where I can select elements in order, highlighting the elements selection.
Please note, Selection.PickObjects() does the selection & highlighting but does not save the elements in the order of Selection.
On
The easiest way you can fix your problem is by using the following method.
public List<Element> GetElementsBySelection(UIDocument uiDoc)
{
bool flag = true;
List<Element> listElem = new List<Element>();
do
{
try
{
Reference referencia = uiDoc.Selection.PickObject(ObjectType.Element);
Element elem = uiDoc.Document.GetElement(referencia);
listElem.Add(elem);
}
catch (Autodesk.Revit.Exceptions.OperationCanceledException e)
{
flag = false;
}
} while (flag);
return listElem;
}
This method ends when you press the "Esc" key. Other more elegant ways to detect when the key is pressed were discussed in the following forums: Monitoring keyboard and Detect key press.
I hope that it serves as a guide so that you can continue advancing in the development. Best regards. Thanks to Jeremy Tammik for the general idea to solve the problem.
It is exactly as you say. No, the Revit API does not provide a built-in method providing the functionality you require. You can implement it yourself by calling
PickObjectrepeatedly in a loop and collecting the selected elements in your own sorted list.