Hi all,
I want to make a function in python script that recursively calls itself until it reaches a element that is not a part, because sometimes the source element of a part is also a part. But my code is always returning the input.
I could(maybe) use a while loop but I am trying to better understand recursion and python.
Here is my code:
import sys
from Autodesk.Revit.DB import *
from Autodesk.Revit.UI import UIApplication
import RevitServices
from RevitServices.Persistence import DocumentManager
def GetParentRecursive(doc,elem):
if type(elem) is Part:
sElem = doc.GetElement(elem.GetSourceElementIds().get_item[0].HostElementId)
return GetParentRecursive(doc,sElem)
else:
return elem
elem = IN[0]
doc = DocumentManager.Instance.CurrentDBDocument
result = GetParentRecursive(doc,elem)
OUT = result