Sort Objects by Selection Order

list-filter
revit
dynamo
python
#1

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.

#2

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

1 Like
#3

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

#4

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

#5

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

#6

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

import clr

clr.AddReference("RevitAPI")
import Autodesk
from Autodesk.Revit.DB import *

clr.AddReference("RevitAPIUI")
from  Autodesk.Revit.UI import *

clr.AddReference("RevitServices")
import RevitServices
from RevitServices.Persistence import DocumentManager
doc = DocumentManager.Instance.CurrentDBDocument
uidoc = DocumentManager.Instance.CurrentUIApplication.ActiveUIDocument
sel1 = uidoc.Selection
obt1 = Selection.ObjectType.Element

clr.AddReference("RevitNodes")
import Revit
clr.ImportExtensions(Revit.Elements)

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
		else:
			return False
	def AllowReference(self, ref, point):
		return True

out1 = []
lst_filter = []
flag = True

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

OUT = out1
#7

Thank you. Will give it a try.