Sort Objects by Selection Order

Hello. I’m still a beginner with Dynamo and had a question that came up at the office today: Is there a way to sort a list of selected objects by the order an object was selected? I understand how to filter an object and sort a list by id, name, etc. However, I have a condition (in the Python code) where I’m allowing the user to manually select objects desired. Is there a way to generate a list of the objects manually selected and keep the same order the objects were selected?

Thanks in advance for your assistance.

I think it’s the Rhythm or Springs package that has a node for just that.


Not trying to high-jack this thread as I work with aperez and he actually asked the question for me. I tried both the Rhythm and Springs packages and neither one does exactly as needed. They both do keep the selection order, however they utilize the PickObject method where the highlight disappears when the next object is selected. Ultimately, what I would like is to utilize the PickObjects method where the objects stay highlighted after selection. This is so the user knows which objects they have already selected to keep from selecting an object twice.

Thank you

As far as I know this is not possible. (Although I am hope I am wrong)

Yeah, that’s what I was afraid the response was going to be.
I appreciate all input!

an alternative with the ‘ISelectionFilter’ class (interface UI) to avoid a new selection already made

import clr

import Autodesk
from Autodesk.Revit.DB import *

from  Autodesk.Revit.UI import *

import RevitServices
from RevitServices.Persistence import DocumentManager
doc = DocumentManager.Instance.CurrentDBDocument
uidoc = DocumentManager.Instance.CurrentUIApplication.ActiveUIDocument
sel1 = uidoc.Selection
obt1 = Selection.ObjectType.Element

import Revit

class CustomISelectionFilter(Selection.ISelectionFilter):
	def __init__(self, lst_f):
		self.lst_f = lst_f
	def AllowElement(self, e):
		if e.Id not in self.lst_f:
			return True
			return False
	def AllowReference(self, ref, point):
		return True

out1 = []
lst_filter = []
flag = True

while flag:
		el1 = doc.GetElement(sel1.PickObject(obt1, CustomISelectionFilter(lst_filter), "Select a element, type escape to finish").ElementId)
	except :
		flag = False

OUT = out1

Thank you. Will give it a try.

Here is another example I found today how to narrow it down to one category:

1 Like