Iterate works with firstobject, not with tagobject



  • On 30/10/2014 at 08:58, xxxxxxxx wrote:

    Hi,

    I have a project which contains these methods:

    def GetNextObject(self, 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(self, op) :
          if op is None:
              return

    count = 0

    while op:
              count += 1
              print op.GetName()
              op = self.GetNextObject(op)

    return count

    Inside Init I call IterateHierarchy; if I do it with the first object, he prints all my objects.
    However when I try to do it with the tagobject it returns None Objects.

    I get them by this:
    global firstobject
    firstobject = doc.GetFirstObject()
    global tagobject
    tagobject = tag.GetObject()

    Does anybody see the problem here?
    Thanks in advance for your awesome help! :D



  • On 30/10/2014 at 16:22, xxxxxxxx wrote:

    Well, for one "tag" isn't a predefined variable. You'll need to find it using

    doc.GetActiveTag()
    

    In addition to that, the tag needs to be selected for it to be found.

    Also, for your method to print all of the objects in your scene, you need to select a tag on the very first object in the scene. This works for me:

      
    import c4d   
    from c4d import gui   
    #Welcome to the world of Python   
      
    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   
      
        count = 0   
      
        while op:   
            count += 1   
            print op.GetName()   
            op = GetNextObject(op)   
      
        return count   
      
    def main() :   
        if (doc is None) or (not doc.IsAlive()) :   
            return   
           
        firstobject = doc.GetFirstObject()   
        if (firstobject is None) or (not firstobject.IsAlive()) :   
            return   
           
        tag = doc.GetActiveTag()   
        if (tag is None) or (not tag.IsAlive()) :   
            return   
           
        tagobject = tag.GetObject()   
           
        IterateHierarchy(tagobject)   
      
    if __name__=='__main__':   
        main()   
      
    

    Perhaps you want to find the first object in your scene from a tag? Try:

    first_object = tag.GetDocument().GetFirstObject()
    

Log in to reply