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

    IsolateObjects question

    Cinema 4D SDK
    r20 python
    3
    7
    773
    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.
    • P
      pim
      last edited by

      I want to store an object and its children into a external file using following script.

      import c4d
      from c4d import gui
      
      # Main function
      def main():
      
          sel = doc.GetSelection()
          newDoc = c4d.documents.IsolateObjects(doc, sel)
          
          c4d.documents.SaveDocument(newDoc, "isolated_objects.c4d", 0, c4d.FORMAT_C4DEXPORT)
          c4d.EventAdd
      
      # Execute main()
      if __name__=='__main__':
          main()
      

      However, if I try to export following object with its children (I selected all objects manually),
      d16f92ec-ea20-47b7-aeba-3d7fb6e21207-image.png

      the hierarchy is not correct and also the original objects are in the scene file?
      903bdf6f-458e-42ae-bc06-38abe4468f5e-image.png

      What am I doing incorrect?
      Is it because the selection is incorrect, not taking into account the hierarchy.
      If so, how can I select the objects and its children withthe correct hierarchy?

      -Pim

      ferdinandF 1 Reply Last reply Reply Quote 0
      • ferdinandF
        ferdinand @pim
        last edited by ferdinand

        Hi,

        sel = doc.GetSelection()
        

        BaseDocument.GetSelection() will return all selected materials, tags and objects. Unless this was an intentional choice, BaseDocument.GetActiveObjects() would be a more appropriate choice.

        newDoc = c4d.documents.IsolateObjects(doc, sel)
        

        You are passing here sel to IsolateObjects() as the argument of the objects to be isolated. Since you selected your whole scene graph this will result in this somewhat self-recursive output you have encountered. Copying Cube from your example also means copying all its descendants (Bend, Cylinder, Sphere and Cone). If you also pass all descendants it will result in the output shown above. So, if you just want to get a copy of Cube and all its children, you just need to select Cube and execute (op is predefined as the selected object) the following:

        new_doc = c4d.documents.IsolateObjects(doc, op)
        

        Cheers
        zipit

        MAXON SDK Specialist
        developers.maxon.net

        P 1 Reply Last reply Reply Quote 0
        • ManuelM
          Manuel
          last edited by Manuel

          hello,

          this is related to that thread i guess. (I also added element there)

          As @zipit said, all the selected element are passed to the isolate function, so that's the result you have. All element and their children isolated one by one.

          You have to only call isolate on the cube.

          Cheers,
          Manuel

          MAXON SDK Specialist

          MAXON Registered Developer

          P 1 Reply Last reply Reply Quote 0
          • P
            pim @ferdinand
            last edited by

            @zipit Thanks, just selecting the cube works.
            One remark using op will give you an error "TypeError: 'c4d.BaseObject' object is not iterable".

            So, just select the cube and

            sel = doc.GetSelection()
            

            will do the trick.

            ferdinandF 1 Reply Last reply Reply Quote 0
            • P
              pim @Manuel
              last edited by

              @m_magalhaes Yes, it is related to the other thread, but let's continue there.

              1 Reply Last reply Reply Quote 0
              • ferdinandF
                ferdinand @pim
                last edited by

                @pim said in IsolateObjects question:

                @zipit Thanks, just selecting the cube works.
                One remark using op will give you an error "TypeError: 'c4d.BaseObject' object is not iterable".

                So, just select the cube and

                sel = doc.GetSelection()
                

                will do the trick.

                Hi,

                sorry, my bad, that was a typo, IsolateObjects() expects a list of BaseObjects. So the the the correct call would be:

                new_doc = c4d.documents.IsolateObjects(doc, [op])
                

                Cheers
                zipit

                MAXON SDK Specialist
                developers.maxon.net

                1 Reply Last reply Reply Quote 0
                • P
                  pim
                  last edited by

                  Aha, thanks.

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