Maxon Developers Maxon Developers
    • Documentation
      • Cinema 4D Python API
      • Cinema 4D C++ API
      • Cineware 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

    Type Error when inserting geometry from a loaded file

    Cinema 4D SDK
    python 2023 windows
    2
    3
    393
    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.
    • D
      datamilch
      last edited by datamilch

      Hi there,
      I'm getting a strange TypeError:

      TypeError: descriptor 'InsertObject' for 'c4d.documents.BaseDocument' objects doesn't apply to a 'c4d.BaseObject' object
      

      When I print the object I want to insert I get a normal output:

      <c4d.BaseObject object called helper - cutplane/Null with ID 5140 at 2616415521856>
      

      The plugin is quite complex at this point, so I try to post only the relevant parts of the code. It's a dialog plugin. Checking for the Main Thread sais True.
      Not sure if I made some obvious mistake ...

      the file structure:
      main.pyp
      src-folder ---- helper py

      in the helper py there are a few classes, that are simplified in the following code:

      class Cutplane:
          ...
          class Helper:
              def load_file(self, filename: str = ''):          
                  folder_path  = os.path.dirname(os.path.abspath(__file__))
                  file_path    = os.path.join( folder_path, filename )
                  loaded_doc = documents.LoadDocument( file_path, c4d.SCENEFILTER_OBJECTS )
                  loaded_obj = loaded_doc.GetFirstObject().GetClone()
                  c4d.documents.KillDocument(loaded_doc)
                  return loaded_obj
      
      
              def load_helper(self):
                  loaded_obj = self.load_file("helper_cutplane_01.c4d")
                  doc = c4d.documents.BaseDocument           
                  print(loaded_obj)
                  print(c4d.threading.GeIsMainThread())
                  doc.InsertObject( loaded_obj )
                  c4d.EventAdd()
      
      i_mazlovI 1 Reply Last reply Reply Quote 0
      • i_mazlovI
        i_mazlov @datamilch
        last edited by

        Hi @datamilch ,

        Thank you for a well structured question!

        Please check the line:

        doc = c4d.documents.BaseDocument
        

        where you assign class type to variable doc instead of the class instance. I assume you meant there

        doc = c4d.documents.BaseDocument()
        

        Cheers,
        Ilia

        MAXON SDK Specialist
        developers.maxon.net

        D 1 Reply Last reply Reply Quote 0
        • D
          datamilch @i_mazlov
          last edited by

          @i_mazlov thanks ilia!!!

          ok that was truly obvious 😬

          actually had to use 'c4d.documents.GetActiveDocument()' to make it work in my case ...

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