I am working on a script that will eventually be a Grasshopper Player plugin with a Humain UI, and it’ll allow the user to select specific objects from the Revit model, in this cenario a railing, and pull it into Grasshopper, and eventually baking that railing into Rhino, then the user will edit the path, etc and then bring it back to Revit as a railing.
I am currently stuck at finding a solution to create a button that picks the objects from Revit, and I’d prefer to find a solution other than running a python script, but I can understand if there’s no other way.
It would be great if the user selects all the objects that they want to be transferred to Rhino first, then they select the button in Human UI. That way the user can ‘select all instances in view’ for example, or just simply select one object.
I am working on a script that will select elements in Revit in Human UI:
It’s not working yet, any help is welcome:
import clr
clr.AddReference('RhinoInside.Revit')
import RhinoInside
from RhinoInside.Revit import Revit, Convert
clr.ImportExtensions(Convert.Geometry)
clr.AddReference('RevitAPI')
import Autodesk
from Autodesk.Revit.DB import RevitLinkInstance
from Autodesk.Revit.Exceptions import OperationCanceledException
clr.AddReference('RevitAPIUI')
from Autodesk.Revit.UI import *
from Autodesk.Revit.UI.Selection import *
import datetime
from datetime import datetime
doc = Revit.ActiveDBDocument
uidoc = Revit.ActiveUIDocument
try:
elemInLinks
except:
elemInLinks = []
try:
elemIDs
except:
elemIDs = []
sel = True # Ensure selection runs
if sel:
TaskDialog.Show("Create Selection", "Select elements and press Finish")
try:
reflnk = uidoc.Selection.PickObjects(ObjectType.Element, "Select elements")
elemInLinks = []
elemIDs = []
for ref in reflnk:
try:
# Attempt to get linked element via LinkedElementId
lnkinst = doc.GetElement(ref.ElementId)
if isinstance(lnkinst, RevitLinkInstance):
doclnk = lnkinst.GetLinkDocument()
elemInLink = doclnk.GetElement(ref.LinkedElementId)
if elemInLink and elemInLink.Id.IntegerValue not in elemIDs:
elemInLinks.append(elemInLink)
elemIDs.append(elemInLink.Id.IntegerValue)
else:
# Local element fallback
elem = doc.GetElement(ref.ElementId)
if elem and elem.Id.IntegerValue not in elemIDs:
elemInLinks.append(elem)
elemIDs.append(elem.Id.IntegerValue)
except:
# Always fallback to local
elem = doc.GetElement(ref.ElementId)
if elem and elem.Id.IntegerValue not in elemIDs:
elemInLinks.append(elem)
elemIDs.append(elem.Id.IntegerValue)
except:
pass
if len(elemInLinks) > 1:
_Elements = elemInLinks
elif len(elemInLinks) == 1:
_Elements = elemInLinks[0]
else:
_Elements = []`
But I get an empty out element, would you know what is wrong ?
type or paste code here