On 16/08/2018 at 15:00, xxxxxxxx wrote:
This problem was seemingly simple to solve but is giving me a hard time. I have the standard procedure for iterating through the object hierarchy from a selected object but I don't want it to keep going after the last object in the immediate hierarchy. I'm using this as a starting point:
def GetNextObject(op) : if op==None: return None if op.GetDown() : return op.GetDown() while not op.GetNext() and op.GetUp() : op = op.GetUp() return op.GetNext() def IterateHierarchy(op) : if op is None: return while op: op = GetNextObject(op) def main() : start_object = doc.GetActiveObject()
So far the only way I've found to get it to search within the immediate hierarchy only is to give IterateHierarchy function the same argument twice, which is the active object, so I can have a reference to the original object while the other is getting replaced by the next object in the sequence . I want the code to say "if you get back to the active object(original object) then end the loop. It seems a bit sloppy the way I did it and i'm sure I am doing wrong. Is there an easier way to start from an object and only search from there down?