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
    • Unread
    • Recent
    • Tags
    • Users
    • Login

    How to group objects with Python?

    Scheduled Pinned Locked Moved PYTHON Development
    4 Posts 0 Posters 770 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

      THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

      On 17/03/2011 at 13:35, xxxxxxxx wrote:

      Hi,

      I am still new to C4D Python but not Python in general.

      I was wondering how one would go about grouping some objects of a selection into a group, as in selecting some objects in the Object Manager and hitting Ctrl+G/Cmd+G.
      It would be great if there is some sort of a command that takes a list of c4d objects and groups them.

      However, I have been looking at the Python class hierarchy of the c4d module but I wasn't able to find something to do with grouping.

      Thanks for reading!

      Andre

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

        THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

        On 17/03/2011 at 14:28, xxxxxxxx wrote:

        def GetHNext(op) :   
          if not op: return   
          if op.GetDown() : return op.GetDown()   
          while not op.GetNext() and op.GetUp() :   
              op = op.GetUp()   
          return op.GetNext()   
          
        def GetActiveObjects(doc) :   
          lst = list()   
          op = doc.GetFirstObject()   
          while op:   
              if op.GetBit(c4d.BIT_ACTIVE) == True: lst.append(op)   
              op = GetHNext(op)   
          return lst   
          
        def Group(lst, copy) :   
          null = c4d.BaseObject(c4d.Onull)   
          if copy == True: lst = [i.GetClone() for i in lst]   
          [obj.InsertUnder(null) for obj in lst]   
          return null   
          
        def main() :   
          lst = GetActiveObjects(doc)   
          op = Group(lst,True)   
          doc.InsertObject(op)   
          c4d.EventAdd()   
        

        Is this what you are looking for ? 🙂

        PS: I'm sorry if there's any mistake in list comprehension etc. I am currently on a mobile device.

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

          THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

          On 17/03/2011 at 14:42, xxxxxxxx wrote:

          That Group function is exactly what I was looking for. Thanks a lot!

          One question, if I may:

          Why the

          if op.GetDown() : return op.GetDown()
          

          in

          GetHNext()
          

          ?

          If you want to return next then why go down and stop there?

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

            THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

            On 17/03/2011 at 14:47, xxxxxxxx wrote:

            No problem. 🙂

            You somewhere need to go down in the hierarchy.
            And going down has the highest priority while walking the hierarchy.
            Hard to explain, just test a bit with it.

            Greets,
            Niklas

            1 Reply Last reply Reply Quote 0
            • First post
              Last post