Hello
I want to check if an element is member of a group.
I use the following python script but now i noticed, that it doesn’t work with more list levels.
So i need help to change the code to work with lists of 3 and maybe more levels.
import clr
clr.AddReference('ProtoGeometry')
from Autodesk.DesignScript.Geometry import *
#Die Eingaben für diesen Block werden in Form einer Liste in den IN-Variablen gespeichert.
items = UnwrapElement(IN[0])
def GetGroup(item):
if hasattr(item, "GroupId"): return item.Document.GetElement(item.GroupId)
else: return None
if isinstance(IN[0], list): OUT = [GetGroup(x) for x in items]
else: OUT = GetGroup(items)
Try making a nested loop, changing this:
OUT = [GetGroup(x) for x in items]
for this:
OUT = [[GetGroup(y) for y in x] for x in items]
1 Like
Hello @EdsonMatt , thanks for your help
So you think only the output is the problem?
Had no luck with your suggestion:
import clr
clr.AddReference('ProtoGeometry')
from Autodesk.DesignScript.Geometry import *
#Die Eingaben für diesen Block werden in Form einer Liste in den IN-Variablen gespeichert.
items = UnwrapElement(IN[0])
def GetGroup(item):
if hasattr(item, "GroupId"): return item.Document.GetElement(item.GroupId)
else: return None
if isinstance(IN[0], list): OUT = [GetGroup(x) for x in items]
else: OUT = [[GetGroup(y) for y in x] for x in items]
The issue is that you’re passing a list of lists, but your code is only built to use a List or an Object.
The easiest fix will be to wrap the Python as it is inside a custom node so that Dynamo’s built it lacing will resolve the issue.
1 Like
I forgot to tell. Put the nested loop after the if statement and not after the else one. Like this:
if isinstance(IN[0], list): OUT = [[GetGroup(y) for y in x] for x in items]
else: OUT = GetGroup(items)
1 Like
Now it works, thanks again Edson
import clr
clr.AddReference('ProtoGeometry')
from Autodesk.DesignScript.Geometry import *
items = UnwrapElement(IN[0])
def GetGroup(item):
if hasattr(item, "GroupId"): return item.Document.GetElement(item.GroupId)
else: return None
if isinstance(IN[0], list): OUT = [[GetGroup(y) for y in x] for x in items]
else: OUT = GetGroup(items)
1 Like