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.
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)
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
Oh ok. I will give it a try when I get a chance. Either way, native component would be great.
I ended up creating a Python component to get Active Selection from Revit.
Get Active Selection.gh (2.8 KB)
__author__ = "mbgoker"
__version__ = "2021.09.09"
import clr
clr.AddReference('System.Core')
clr.AddReference('RhinoInside.Revit')
clr.AddReference('RevitAPI')
clr.AddReference('RevitAPIUI')
from System import Enum, Action
import rhinoscriptsyntax as rs
import Rhino
import RhinoInside
import Grasshopper
from Grasshopper.Kernel import GH_RuntimeMessageLevel as RML
from RhinoInside.Revit import Revit, Convert
# add extensions methods as well
# this allows calling .ToXXX() convertor methods on Revit objects
clr.ImportExtensions(Convert.Geometry)
from Autodesk.Revit import DB
from Autodesk.Revit import UI
# access the active document object
doc = Revit.ActiveDBDocument
uidoc = Revit.ActiveUIDocument
# a few utility methods
def show_warning(msg):
ghenv.Component.AddRuntimeMessage(RML.Warning, msg)
def show_error(msg):
ghenv.Component.AddRuntimeMessage(RML.Error, msg)
def show_remark(msg):
ghenv.Component.AddRuntimeMessage(RML.Remark, msg)
element = []
selection = uidoc.Selection
elementid = selection.GetElementIds()
for id in elementid:
e = doc.GetElement(id)
element.append(e)
Hi @mucahitbgoker,
Any âGraphical Elementâ can be used for this purpose as well.
It also allows you to save your selections in the document using âExternalise selectionâ or even reference Rule-Based Filters stored on your document.
Hi Kike this is an very elegant and minimal way to implement it.
I have to admit that I could also only discover it because of this post here.
It might make sense to add a separate component for it, so that users can discover it when searching for âactiveâ together with the other components like active -workset, -document, -graphical view and -design option.
And like Mucahit Iâm also missing a way to reference the active selection of linked elements. Is it just not possible right now, or am I missing out on something.
Thanks in advance, and thanks for your great developement in general!
This is still not an option (preselect linked elements). Iâll create a feature request for a new component named Active Selection with that functionality, would definitely be useful. Thanks.
Hi @mucahitbgoker, Iâm interested, did you find a way to get the active selection of linked elements?
There are several exciting additions to Revit API with linked Elements, unfortunately this particular selection request doesnât appear to be available.
Hereâs what happened when I tried to launch Player with an Active Selection button saved in the script. Revit did not like that.
Can you share your script? I see youâre on Revit 2022, what release of Rhino.Inside.Revit might be relevant as well. Thanks.