Maxon Developers Maxon Developers
    • Documentation
      • Cinema 4D Python API
      • Cinema 4D C++ API
      • Cineware API
      • ZBrush Python API
      • ZBrush GoZ API
      • Code Examples on Github
    • Forum
    • Downloads
    • Support
      • Support Procedures
      • Registered Developer Program
      • Plugin IDs
      • Contact Us
    • Categories
      • Overview
      • News & Information
      • Cinema 4D SDK Support
      • Cineware SDK Support
      • ZBrush 4D SDK Support
      • Bugs
      • General Talk
    • Recent
    • Tags
    • Users
    • Login

    Iterate works with firstobject, not with tagobject

    Scheduled Pinned Locked Moved PYTHON Development
    2 Posts 0 Posters 183 Views
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • H Offline
      Helper
      last edited by

      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! 😄

      1 Reply Last reply Reply Quote 0
      • H Offline
        Helper
        last edited by

        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()
        
        1 Reply Last reply Reply Quote 0
        • First post
          Last post