Getting the current selection in Revit?

How can I use Dynamo to get what’s currently selected? I’m not talking about getting an element ID for a node, I mean a Dynamo script which returns all of the ID’s the user has selected before the Dynamo script is manually run.

1 Like

Cool, thanx! I keep hearing/seeing this springs stuff, going to have to look into it now

Thank you for the answer. This works!
Next question - Is it possible to somehow auto-refresh this node each time the graph is run?
For example - say, if I run the graph, then change my selection in Revit and run the graph again?

In this case I need to manually refresh the node with boolean input. Can this be done automatically?

Dear John pierson,

I have made a script with the current selection. In that script I place some objects on the place of my current selection. When i replay the script with a new selection it doesn’t place the object anymore becouse the current selection say’s empty list. When I remove the node for placing object the current selection works just fine. How is that posible? I play the dynamo script with dyno browser so i can use shortcuts on my keyboard.

First time

Second time

Did a few test this is what I know.

-When I remove the object that has been placed the current selection works fine the second time.
-when it doesn’t have to place objects it works fine the second time. (No empty list and grabs the object I selected).
-When I play it for a thrid time it works fine.

It’s like the current selecion grabs back to the objects that have been placed.

Hope to hear from you.

With kind regards,

TImo Jooren

Hello, @john_pierson, I have used this node with great success for a long time now, however, today when I am trying to use it, it will not run to completion if I have more than one item selected. It just sits there and says “Run started” but never completes, then when I click in the revit screen, delesecting all but one, (or by selecting only one element if you will) It runs just fine. What gives? Ive tried restarting dynamo several times and started the script in both the automatic and manual run, but I cant get it to see more than one element. Please advise.
Thanks you!

image

1 Like

This node is only working with model elements.

Is there a node that can return anything currently selected?
Like e.g. TextNotes in my case.

1 Like

Yes, I’m trying to get it to select a sheet and it doesn’t seem to recognize it.

Hello
some elements (as TextNotes) are specific elements, a workaround with Python by “by-Pass the OUT wrapper”.

import clr

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

clr.AddReference('RevitServices')
import RevitServices
from RevitServices.Persistence import DocumentManager

doc = DocumentManager.Instance.CurrentDBDocument
uiapp = DocumentManager.Instance.CurrentUIApplication
app = uiapp.Application
uidoc = uiapp.ActiveUIDocument

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

ueWrapper = None
wrappers = clr.GetClrType(Revit.Elements.ElementWrapper).GetMethods()
for w in wrappers:
	if w.ToString().startswith("Revit.Elements.UnknownElement"):
		ueWrapper = w
		break
		
out = []
selectElemId = uidoc.Selection.GetElementIds()
selectElem = [doc.GetElement(xId) for xId in selectElemId]

for i in selectElem:
	try:
		check = Revit.Elements.ElementWrapper.Wrap(i, True)
	except: check = None

	if check is None:
		out.append(ueWrapper.Invoke(None, (i, False)))
	else:
		out.append(i) 

OUT = out

you need to Run the script to actually populate the list of the current selection node.
i found that sometimes the list will cling to the last selection, even though i select something else and hit run again.
and even with nothing selected if i click Run script the list will still be populated (with the last selection).

pretty annoying.
or am I missing something?

@bogdan.petrescu63URX you need to change the true/false value to refresh the current selection.

hello,

thank you for the reply.

the default is true so it should work always without changing anything.

and even if i put a true boolean in the refresh input it still does the same, it refreshes whenever it wants. unpredictable.

i sometimes have to freeze the CurrenSelection node, run script, unfreeze node, run script again with nothing selected to finally get the “Empty list” or null…

other times it just works great between changing selected elements. down to pure luck it seems.

when it does not work i just close the script and open it again real quick from the recent list.
takes about 2-3 seconds, a bit annoying but it gets the job done.

It’s not down to luck, I use this node a lot and it works every time.

You need to put a boolean in and toggle between true/false each time you want to update the selection.

Capture

The value of true or false is not important the node will work with both. Changing the value only refreshes the list.

If you don’t change the boolean it will retain the previous information.

If you change it to false and run it again it will update and vice versa.

ok so i want it to change every time by selecting new elements and running the script, so i should leave it on true.
it doesn’t work, sometimes it clings to the previous selection.

if i toggle between true/false in the bool variable nothing happens.
i am using manual execution mode. should i be using automatic?

can you please explain again maybe in different words how to make sure the list is updated to the current selection every time?

thank you!

  • i just enabled automatic mode and toggeling between true/false clears the list!!!

OH MY GOD thank you so much!

1 Like

It should work on both manual or automatic. Each time you want to update the selection you need to run the script again after changing the boolean value. You might want to freeze the nodes after “collect.currentselection” to check it’s updated, this is not essential but might help to understand how its working.

Steps for first run.
1.Select elements in Revit.
2.Run Dynamo Scipt.

steps to refresh current selection node.

  1. Select new elements in Revit.
  2. Change the Boolean value to the opposite value of the previous run.
  3. Run Dynamo script.

and repeat…

Unfortunately, I’ve no screen recording software to demonstrate but I hope that helps.

1 Like

you helped more than you can imagine!
I was not changing the boolean value…

now it is working like a charm!

1 Like