searching immediate hierarchy

  • 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:
        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?

  • On 17/08/2018 at 02:32, xxxxxxxx wrote:

    Hi Motion4D, unfortunately, we can only provide you support for API related question, not algorithm questions.

    But with that said, here is tree way to do it but there is a bunch of others, is up to you to choose the one which will be the more efficient for you:

    1. Pass the next object of the start_object as additional arguments and check if the traversed object is this one, if yes return.
    2. Same things, but instead store the next object in a global variable (don't forget to free this global variable after any usage with del(yourGlobalVariable)
    3. Use recursively GeListNode.GetChildren

    Hope it helps,

  • On 17/08/2018 at 09:45, xxxxxxxx wrote:

    Great suggestions Maxime! You rock!