From 6559e5b666a975649fe486cc11f9d769cfd93769 Mon Sep 17 00:00:00 2001 From: Andreas Dieckmann Date: Sun, 29 Dec 2024 08:57:48 +0100 Subject: [PATCH] #416 python changes --- nodes/3.x/python/All Elements Of Category+.py | 2 +- .../3.x/python/All Family Types Of Category.py | 2 +- ...w-Dependent Family Instances Of Category.py | 2 +- nodes/3.x/python/BuiltInCategory.FromInput.py | 18 +++++++++++------- nodes/3.x/python/Element.Category+.py | 7 ++++--- nodes/3.x/python/Element.SlabShapeByPoints.py | 10 ++++------ nodes/3.x/python/PathGraph.AllPaths.py | 2 +- nodes/3.x/python/PathGraph.ShortestPath.py | 2 +- 8 files changed, 24 insertions(+), 21 deletions(-) diff --git a/nodes/3.x/python/All Elements Of Category+.py b/nodes/3.x/python/All Elements Of Category+.py index c808bd5a..02fb676e 100644 --- a/nodes/3.x/python/All Elements Of Category+.py +++ b/nodes/3.x/python/All Elements Of Category+.py @@ -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 [] diff --git a/nodes/3.x/python/All Family Types Of Category.py b/nodes/3.x/python/All Family Types Of Category.py index efa9f4a5..7c09d281 100644 --- a/nodes/3.x/python/All Family Types Of Category.py +++ b/nodes/3.x/python/All Family Types Of Category.py @@ -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 [] diff --git a/nodes/3.x/python/All View-Dependent Family Instances Of Category.py b/nodes/3.x/python/All View-Dependent Family Instances Of Category.py index f3d2da34..1d78c6b0 100644 --- a/nodes/3.x/python/All View-Dependent Family Instances Of Category.py +++ b/nodes/3.x/python/All View-Dependent Family Instances Of Category.py @@ -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)] diff --git a/nodes/3.x/python/BuiltInCategory.FromInput.py b/nodes/3.x/python/BuiltInCategory.FromInput.py index 8a0298ba..7c4b3ca2 100644 --- a/nodes/3.x/python/BuiltInCategory.FromInput.py +++ b/nodes/3.x/python/BuiltInCategory.FromInput.py @@ -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 diff --git a/nodes/3.x/python/Element.Category+.py b/nodes/3.x/python/Element.Category+.py index edf80e1b..cd8fafa6 100644 --- a/nodes/3.x/python/Element.Category+.py +++ b/nodes/3.x/python/Element.Category+.py @@ -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 @@ -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() diff --git a/nodes/3.x/python/Element.SlabShapeByPoints.py b/nodes/3.x/python/Element.SlabShapeByPoints.py index d219eda6..f928b1cb 100644 --- a/nodes/3.x/python/Element.SlabShapeByPoints.py +++ b/nodes/3.x/python/Element.SlabShapeByPoints.py @@ -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]) diff --git a/nodes/3.x/python/PathGraph.AllPaths.py b/nodes/3.x/python/PathGraph.AllPaths.py index f9e0b7f4..b971acc3 100644 --- a/nodes/3.x/python/PathGraph.AllPaths.py +++ b/nodes/3.x/python/PathGraph.AllPaths.py @@ -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]: diff --git a/nodes/3.x/python/PathGraph.ShortestPath.py b/nodes/3.x/python/PathGraph.ShortestPath.py index db9d52ff..b272011a 100644 --- a/nodes/3.x/python/PathGraph.ShortestPath.py +++ b/nodes/3.x/python/PathGraph.ShortestPath.py @@ -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]: