Selecting Rebar on Python Script


Hello guys, I want to select column reinforcement at the selected level. when I use python script, there is a problem so that the result becomes null. previously I used the package from Genius Loci. Is there any advice that can be given to me? Thanks.

Do you want a Python :snake: solution per se.
What you want can be done with just
nodes AFAIK.

Also post the Python :snake: code
if you need help with that.
Can’t tell what the problem is by
just that image.

I using this script.

#Alban de Chasteigner 2019.txt (5.1 KB)

#Alban de Chasteigner 2019
#twitter : @geniusloci_bim
#geniusloci.bim@gmail.com
#GitHub - albandechasteigner/GeniusLociForDynamo: Genius Loci is a package of 350+ custom nodes for Dynamo in Revit.

import clr
clr.AddReference(‘RevitNodes’)
import Revit
clr.ImportExtensions(Revit.Elements)

clr.AddReference(‘RevitAPI’)
from Autodesk.Revit.DB import Category, FamilySymbol, FilteredElementCollector, Document, RevitLinkInstance, ElementParameterFilter, ElementMulticlassFilter, ElementMulticategoryFilter, FilterElementIdRule, ParameterValueProvider, FilterNumericEquals, ElementId, BuiltInCategory,BuiltInParameter, Level, HostObjAttributes
import System
from System.Collections.Generic import List

def tolist(obj1):
if hasattr(obj1,“iter”): return obj1
else: return [obj1]

SelectedLevel = tolist(UnwrapElement(IN[0]))[0]
cats = tolist(UnwrapElement(IN[1]))
cats2 = tolist(UnwrapElement(IN[2]))

doc = SelectedLevel.Document
elem =

#ueWrapper by Dimitar Venkov
ueWrapper = None
wrappers = clr.GetClrType(Revit.Elements.ElementWrapper).GetMethods()
for w in wrappers:
if w.ToString().startswith(“Revit.Elements.UnknownElement”):
ueWrapper = w
break

provider = ParameterValueProvider(ElementId(BuiltInParameter.ELEM_FAMILY_PARAM))
provider2 = ParameterValueProvider(ElementId(BuiltInParameter.ELEM_TYPE_PARAM))
evaluator = FilterNumericEquals()

for cat in cats:
if isinstance(cat, Category):
catId = List[ElementId](x.Id for x in cats)
filter = ElementMulticategoryFilter(catId)
fec = FilteredElementCollector(doc).WhereElementIsNotElementType()
elif isinstance(cat, System.Type):
catId = ListSystem.Type
filter = ElementMulticlassFilter(catId)
fec = FilteredElementCollector(doc)
elif isinstance(cat, FamilySymbol):
filter = ElementParameterFilter(FilterElementIdRule(provider, evaluator, cat.Id))
fec = FilteredElementCollector(doc).OfCategoryId(cat.Category.Id)
elif isinstance(cat, HostObjAttributes):
filter = ElementParameterFilter(FilterElementIdRule(provider2, evaluator, cat.Id))
fec = FilteredElementCollector(doc).OfCategoryId(cat.Category.Id)
for cat in cats:
if isinstance(cat, Category):
catId = List[ElementId](x.Id for x in cats)
filter = ElementMulticategoryFilter(catId)
fec = FilteredElementCollector(doc).WhereElementIsNotElementType()
elif isinstance(cat, System.Type):
catId = ListSystem.Type
filter = ElementMulticlassFilter(catId)
fec = FilteredElementCollector(doc)
elif isinstance(cat, FamilySymbol):
filter = ElementParameterFilter(FilterElementIdRule(provider, evaluator, cat.Id))
fec = FilteredElementCollector(doc).OfCategoryId(cat.Category.Id)
elif isinstance(cat, HostObjAttributes):
filter = ElementParameterFilter(FilterElementIdRule(provider2, evaluator, cat.Id))
fec = FilteredElementCollector(doc).OfCategoryId(cat.Category.Id)
collector = fec.WherePasses(filter)
#Inspired by Clockwork
def GetLevel(item):
val = None
if hasattr(item, “LevelId”):
val = item.Document.GetElement(item.LevelId)
if val: return val
if hasattr(item, “Level”):
val = item.Level
if val: return val
if hasattr(item, “GenLevel”):
val = item.GenLevel
if val: return val
if (item.GetType().ToString() in (“Autodesk.Revit.DB.Architecture.StairsRun”, “Autodesk.Revit.DB.Architecture.StairsLanding”)):
item = item.GetStairs()
if (item.GetType().ToString() == “Autodesk.Revit.DB.Architecture.Stairs”) or item.Category.Id == ElementId(BuiltInCategory.OST_Ramps):
try: return item.Document.GetElement(item.get_Parameter(BuiltInParameter.STAIRS_BASE_LEVEL_PARAM).AsElementId())
except: pass
if (item.GetType().ToString() == “Autodesk.Revit.DB.ExtrusionRoof”):
try: return item.Document.GetElement(item.get_Parameter(BuiltInParameter.ROOF_CONSTRAINT_LEVEL_PARAM).AsElementId())
except: pass
if (item.GetType().ToString() == “Autodesk.Revit.DB.Mechanical.Duct” or “Autodesk.Revit.DB.Electrical.Conduit”):
try: return item.Document.GetElement(item.get_Parameter(BuiltInParameter.RBS_START_LEVEL_PARAM).AsElementId())
except: pass
if hasattr(item, “OwnerViewId”):
view = item.Document.GetElement(item.OwnerViewId)
if hasattr(view, “GenLevel”):
val = view.GenLevel
if val: return val
if not val:
try: return item.Document.GetElement(item.get_Parameter(BuiltInParameter.INSTANCE_REFERENCE_LEVEL_PARAM).AsElementId())
except:
try: return item.Document.GetElement(item.get_Parameter(BuiltInParameter.INSTANCE_SCHEDULE_ONLY_LEVEL_PARAM).AsElementId())
except:
try: return item.Document.GetElement(item.get_Parameter(BuiltInParameter.SCHEDULE_LEVEL_PARAM).AsElementId())
except:
#if item is work plane based
collector = FilteredElementCollector(item.Document).OfClass(Level).ToElements()
try: return [level for level in collector if item.get_Parameter(BuiltInParameter.SKETCH_PLANE_PARAM).AsString().split(": ")[-1] == level.Name][0]
except: return None

for col in collector :
if GetLevel(col) and GetLevel(col).Id == SelectedLevel.Id:
try:
elem.append(col.ToDSType(True))
except:
if ueWrapper:
elem.append(ueWrapper.Invoke(None,(col, True)))

OUT = elem
collector.Dispose()
filter.Dispose()

Post the Python in preformatted text next time :wink:

Your Python

But you didn’t really answer my question.
Can the solution be a non Python one?
If no, then i can’t help you. I don’t know any Python.

And did you use a node in the past which doesn’t work anymore?

2 Likes

Thanks for advice, i will try to my dynamo.

Sorry sir. Where can i find Rebars.Host’s node?

1 Like