I found this answer by @Konrad_K_Sobon on SO about how to make a python script handle different list structures, but for some reason it’s not working on a different function and I can’t figure out why. I guess it’s the unwrapping that’s causing problems.
I’m getting AttributeError: ‘List[object]’ object has no attribute ‘ViewType’. It’s not supposed to call the passed function on the object if it’s a list, but it seems it’s not recognizing this unwrapped List[object]. How can I get around this?
#Function to handle any list structure
ProcessLists = lambda function, lists: [ProcessLists(function, item) if isinstance(item, list) else function(item) for item in lists]
ApplyFunction = lambda func, objs: ProcessLists(func, objs) if isinstance(objs, list) else [func(objs)]
#Funtion to unwrap
def Unwrap(item):
return UnwrapElement(item)
#Preparing input from dynamo to revit
if isinstance(IN[0], list):
views = ProcessLists(Unwrap, IN[0])
else:
views = Unwrap(IN[0])
#Define function to get view type
def getViewType(view):
return view.ViewType
#OUTPUT
OUT = ApplyFunction(getViewType,views)
That definitely has a much better ring to it and you didn’t fail to deliver
Thanks Kulkul! Could you maybe let me know why we need the ApplyFunction = lambda func, objs: ProcessLists(func, objs) if isinstance(objs, list) else [func(objs)]
line here? I’m still trying to wrap my head around how it all actually works.
Oh I did learn about lambdas just a few days ago, but I couldn’t figure out how exactly you’re using it in this case. I guess I’ll just have to dissect your code more closely to understand when I have some time.