Answers for "get element selected dynamo revit"

0

get element selected dynamo revit

import clr

clr.AddReference("RevitServices")
import RevitServices
from RevitServices.Persistence import DocumentManager
from System.Collections.Generic import List

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

def tolist(obj1):
	if hasattr(obj1,'__iter__'): return obj1
	else: return [obj1]

def flatten(x):
    result = []
    for el in x:
        if hasattr(el, "__iter__") and not isinstance(el, basestring):
            result.extend(flatten(el))
        else:
            result.append(el)
    return result

elements = UnwrapElement(flatten(tolist(IN[0])))

selected = []
Icollection = List[ElementId]()
for e in elements:
	try:
		Icollection.Add(e.Id)
		selected.append(e)
	except:
		pass
DocumentManager.Instance.CurrentUIApplication.ActiveUIDocument.Selection.SetElementIds(Icollection)

OUT = selected
Posted by: Guest on July-04-2021

Browse Popular Code Answers by Language