Skip to content

Commit

Permalink
#416 python changes
Browse files Browse the repository at this point in the history
  • Loading branch information
andydandy74 committed Dec 29, 2024
1 parent 56bbeda commit 6559e5b
Show file tree
Hide file tree
Showing 8 changed files with 24 additions and 21 deletions.
2 changes: 1 addition & 1 deletion nodes/3.x/python/All Elements Of Category+.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

def ElementsByCategory(bic, doc):
if bic:
collector = FilteredElementCollector(doc).OfCategory(bic).WhereElementIsNotElementType()
collector = FilteredElementCollector(doc).OfCategory(eval("BuiltInCategory."+bic)).WhereElementIsNotElementType()
return collector.ToElements()
else: return []

Expand Down
2 changes: 1 addition & 1 deletion nodes/3.x/python/All Family Types Of Category.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

def ElementTypesByCategory(bic, doc):
if bic:
collector = FilteredElementCollector(doc).OfCategory(bic).WhereElementIsElementType()
collector = FilteredElementCollector(doc).OfCategory(eval("BuiltInCategory."+bic)).WhereElementIsElementType()
return collector.ToElements()
else: return []

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
def CollectByView(bic, view):
collector = FilteredElementCollector(doc)
filter = ElementOwnerViewFilter(view.Id)
return collector.WherePasses(filter).OfCategory(bic).ToElements()
return collector.WherePasses(filter).OfCategory(eval("BuiltInCategory."+bic)).ToElements()

def GetViewDependentElements(cat, views):
if isinstance(views, list): return [CollectByView(cat, x) for x in UnwrapElement(views)]
Expand Down
18 changes: 11 additions & 7 deletions nodes/3.x/python/BuiltInCategory.FromInput.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,17 @@

def GetBicFromInput(var):
if var:
cattype = var.GetType().ToString()
if cattype == "Revit.Elements.Category": return System.Enum.ToObject(BuiltInCategory, var.Id)
elif cattype == "Autodesk.Revit.DB.BuiltInCategory": return var
elif cattype == "System.String":
found = [x for x in bics if x.ToString() == var]
if len(found) > 0: return found[0]
else: return None
if isinstance(var, str):
try:
eval("BuiltInCategory." + var)
return var
except: return None
elif isinstance(var, int): return System.Enum.GetName(BuiltInCategory, var)
else:
cattype = var.GetType().ToString()
if cattype == "Revit.Elements.Category": return System.Enum.GetName(BuiltInCategory, var.Id)
elif cattype == "Autodesk.Revit.DB.BuiltInCategory": return var
else: return None
else: return None

doc = DocumentManager.Instance.CurrentDBDocument
Expand Down
7 changes: 4 additions & 3 deletions nodes/3.x/python/Element.Category+.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@

def GetCategory(item):
if not item: return None, None
objtype = item.GetType().ToString()
objtype = None
if hasattr(item, "GetType"): objtype = item.GetType().ToString()
returnID = None
returnIDs = None
returnCat = None
Expand All @@ -30,14 +31,14 @@ def GetCategory(item):
elif hasattr(item, "Category"):
if item.Category: returnID = item.Category.Id
if returnID:
returnBic = System.Enum.ToObject(BuiltInCategory, returnID.IntegerValue)
returnBic = System.Enum.GetName(BuiltInCategory, returnID.IntegerValue)
try: returnCat = Revit.Elements.Category.ById(returnID.IntegerValue)
except: pass
elif returnIDs:
returnCat = []
returnBic = []
for returnID in returnIDs:
returnBic.append(System.Enum.ToObject(BuiltInCategory, returnID.IntegerValue))
returnBic.append(System.Enum.GetName(BuiltInCategory, returnID.IntegerValue))
try: returnCat.append(Revit.Elements.Category.ById(returnID.IntegerValue))
except: returnCat.append(None)
returnCat.sort()
Expand Down
10 changes: 4 additions & 6 deletions nodes/3.x/python/Element.SlabShapeByPoints.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,10 @@ def AddPointToSlabShape(item, point):
if hasattr(item, "SlabShapeEditor"): sle = item.SlabShapeEditor
elif hasattr(item, "GetSlabShapeEditor"): sle = item.GetSlabShapeEditor()
else: return False
if hasattr(point, "ToXyz"):
try:
sle.DrawPoint(point.ToXyz())
return True
except: return False
else: return False
try:
sle.DrawPoint(point.ToXyz())
return True
except: return False

doc = DocumentManager.Instance.CurrentDBDocument
items = UnwrapElement(IN[1])
Expand Down
2 changes: 1 addition & 1 deletion nodes/3.x/python/PathGraph.AllPaths.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ def find_all_paths(graph, start, end, path=[]):
path = path + [start]
if start == end:
return [path]
if not graph.has_key(start):
if start not in graph:
return []
paths = []
for node in graph[start]:
Expand Down
2 changes: 1 addition & 1 deletion nodes/3.x/python/PathGraph.ShortestPath.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ def find_shortest_path(graph, start, end, path=[]):
path = path + [start]
if start == end:
return path
if not graph.has_key(start):
if not start in graph:
return None
shortest = None
for node in graph[start]:
Expand Down

0 comments on commit 6559e5b

Please sign in to comment.