Node for Picking Elements in Order with Revit UI

I was wondering if there’s any node to pick multiple elements in order that uses the object picking UI (Finish/Cancel) and has the option of deselecting last picks using Shift + Right Click.

there is one in datashape package. select in order

Here is one for springs

2 Likes

That does not have the option bar buttons and the deselect last picks feature. It’s a bit confusing at times what elements you selected.

the idea of selecting in order is to put select element in a loop usuing python, so i think there is no option of deselecting while selecting. you may make an additional step to show your selection using eg. listView in datashape also so you can select what you want and neglect the others

1 Like

Here in this video you can see the PickObjects method where the pointer has + and - sign. At the end you can simply click on Finish in the options bar.

PickObjects Method in Dynamo - YouTube

this is standalone addin, you can make something similar to it, using UI in datashape again , make 2 button , + and - , make them both to select elements , the final result will be substracting the elements selected in the - button from the elements selected in the + button

1 Like

Ordered selection with the finish button is not possible in the API.

The workaround that we have all been using for a while now is what you are experiencing. Pick each element (singular) in a loop and add to a list.

This came up quite a while back on the Autodesk Revit API forums and that is where the solution was presented.

3 Likes

Sometimes if you’re not careful, you might miss picking one or two items from in a long chain of selection. If the selected items get faded or highlighted blue, it’d be a great help. Deselection would be an added advantage.

Agreed. Another option might be to use the selection with the finish option, but sort the elements after the fact by some criteria/parameters?

2 Likes

An idea of workaround

OrderSelection

import clr
import sys
import System

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

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

from System.Collections.Generic import List

clr.AddReference('RevitServices')
import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager
doc = DocumentManager.Instance.CurrentDBDocument
uiapp = DocumentManager.Instance.CurrentUIApplication
uidoc = uiapp.ActiveUIDocument

def overridecolor(elementId, reset = False):
	t = Transaction(doc, "Selection")
	t.Start()
	view = doc.ActiveView
	color_rgb = DB.Color(30,144,255)
	gSettings = OverrideGraphicSettings()
	if not reset: 
		gSettings.SetSurfaceForegroundPatternColor(color_rgb) 
		gSettings.SetProjectionLineColor(color_rgb)
		gSettings.SetCutLineColor(color_rgb)
		gSettings.SetCutForegroundPatternColor(color_rgb)
		gSettings.SetProjectionLineWeight(8)
	view.SetElementOverrides(elementId, gSettings)
	doc.Regenerate()
	uidoc.RefreshActiveView()
	t.Commit()
	t.Dispose()
			
		
flag = True
selectId = []
TransactionManager.Instance.ForceCloseTransaction()
TaskDialog.Show('Selection', 'Pick elements in the desired order (re-select to Remove), hit ESC to stop picking.')
tg = TransactionGroup(doc, "Selection")
tg.Start()
while flag:
	try:
		ref = uidoc.Selection.PickObject(ObjectType.Element, 'Pick elements in the desired order (re-select to Remove), hit ESC to stop picking.')
		e_id = ref.ElementId
		if e_id not in selectId:
			overridecolor(e_id)
			selectId.append(e_id)
		else:
			overridecolor(e_id, True)
			selectId.pop(selectId.index(e_id))
			
	except Exception as ex:
		flag = False
		break		
tg.RollBack()
elemenSelect = [doc.GetElement(xId) for xId in selectId]

OUT = elemenSelect

2nd Example with input Category selection

import clr
import sys
import System

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

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

from System.Collections.Generic import List

clr.AddReference('RevitServices')
import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager
doc = DocumentManager.Instance.CurrentDBDocument
uiapp = DocumentManager.Instance.CurrentUIApplication
uidoc = uiapp.ActiveUIDocument

class CustomSelectionElem(ISelectionFilter):
	def __init__(self, catIdValue):
		self.catIdValue = catIdValue
	def AllowElement(self, e):
		if e.Category.Id == ElementId(self.catIdValue):
			return True
		else:
			return False
	def AllowReference(self, ref, point):
		return True 

def overridecolor(elementId, reset = False):
	t = Transaction(doc, "Selection")
	t.Start()
	view = doc.ActiveView
	color_rgb = DB.Color(30,144,255)
	gSettings = OverrideGraphicSettings()
	if not reset: 
		gSettings.SetSurfaceForegroundPatternColor(color_rgb) 
		gSettings.SetProjectionLineColor(color_rgb)
		gSettings.SetCutLineColor(color_rgb)
		gSettings.SetCutForegroundPatternColor(color_rgb)
		gSettings.SetProjectionLineWeight(8)
	view.SetElementOverrides(elementId, gSettings)
	doc.Regenerate()
	uidoc.RefreshActiveView()
	t.Commit()
	t.Dispose()
			

catIdValue = IN[0].Id
flag = True
selectId = []
TransactionManager.Instance.ForceCloseTransaction()
TaskDialog.Show('Selection', 'Pick elements in the desired order (re-select to Remove), hit ESC to stop picking.')
tg = TransactionGroup(doc, "Selection")
tg.Start()
while flag:
	try:
		ref = uidoc.Selection.PickObject(ObjectType.Element, CustomSelectionElem(catIdValue), 'Pick elements in the desired order (re-select to Remove), hit ESC to stop picking.')
		e_id = ref.ElementId
		if e_id not in selectId:
			overridecolor(e_id)
			selectId.append(e_id)
		else:
			overridecolor(e_id, True)
			selectId.pop(selectId.index(e_id))
			
	except Exception as ex:
		flag = False
		break		
tg.RollBack()
elemenSelect = [doc.GetElement(xId) for xId in selectId]

OUT = elemenSelect
14 Likes

This is exactly what I need. If only data-shapes would have this feature. @Mostafa_El_Ayoubi