Hey,
Is it possible to get the Autodes.Revit.DB.Reference from an ElementID.
I want to collect my current selection in revit and get the Autodes.Revit.DB.Reference from my selected elements. But i only seem to be able to get the ElementID using GetElementIds() so i want to translate those to References
What is your end goal, What will you use the element for?
Do you have the code so that we can try?
1 Like
Thanks for your reply but i fixed it already!
import Autodesk
from Autodesk.Revit.DB import *
from Autodesk.Revit.UI import *
import clr
clr.AddReference("RevitServices")
from RevitServices.Transactions import TransactionManager
#----------------------------DOCUMENT---------------------------------------------------------------------
doc = __revit__.ActiveUIDocument.Document
uidoc = __revit__.ActiveUIDocument
view = doc.ActiveView
#----------------------------TRANSACTION------------------------------------------------------------------
t = Transaction(doc, "Transaction")
t.Start()
#----------------------------DEFINITIONS------------------------------------------------------------------
def flatten(l):
return [item for sublist in l for item in sublist]
def filter(a,b):
UIT = []
for i in a:
Element = doc.GetElement(i)
z = Element.Category.Name
if z in b:
UIT.append(i)
return UIT
#----------------------------SCRIPT----------------------------------------------------------------------
Filter = ["Electrical Fixtures", "Lighting Fixtures","Lighting Devices","Data Devices","Communication Devices","Fire Alarm Devices"];
Sel = uidoc.Selection.GetElementIds()
SelFil = filter(Sel, Filter)
Parameter1 = []
Parameter2 = []
for i in SelFil:
Element = doc.GetElement(i)
Referentie = Reference(Element)
Locatie = Element.Location.Point
IndependentTag.Create(doc, view.Id, Referentie, False, TagMode.TM_ADDBY_MULTICATEGORY, TagOrientation.Horizontal, Locatie)
Parameter1.append(Element.GetParameters("Offset from Host")) #Parameter om uit te lezen
Parameter2.append(Element.GetParameters("Ass. Level Elevation Center")) #Parameter om uit te lezen
Parameter1 = flatten(Parameter1)
Parameter2 = flatten(Parameter2)
Value = []
for i in Parameter1:
p = i.AsDouble()
Value.append(p)
sequence = zip(Parameter2, Value)
for u, y in sequence:
u.Set(y)
#----------------------------TRANSACTION------------------------------------------------------------------
t.Commit()
1 Like