Get Elements in Active Selection

Hi guys,

How can I access selected elements in Grasshopper? I am planning to create a script and distribute it in my company. So users can select some elements and modify them throug Revit Interface.

Like Grasshopper Player! I know that’s been discussed but not seeing the Feature Request. I’ll get more info on this and get back to you.

Possible workarounds…
It could be parameter driven, if the idea is that a user just opens a particular script to ‘do something’ on the 4 walls you could have a Text Parameter that they add a value to, which the script would be able to gather the Elements ‘do something’ and clear the parameter.

For instance, I have rooms in the floorplan and I want the user to only select rooms and click the script. Then script will generate floor from room boundaries.

I am making the selection before running the script.

Other way around is also works. First start the script then select elements. Script will do its thing.

Here’s what i was thinking.

You select the Elements and add a Yes to the parameter, then use grasshopper player to run the script.

Re_RhinoInsidePlayer.rvt (1.5 MB) Revit 2022
RhinoInsidePlayer.gh (8.6 KB)

1 Like

This is a hacky way to do. It works you are right but I would definitely prefer just making a selection then running it.

First post here, Hi,
you might want to try something in Python, the syntax below is Dynamo4Revit related but should be easily adaptable

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
2 Likes

Oh ok. I will give it a try when I get a chance. Either way, native component would be great.