Type Error when inserting geometry from a loaded file
-
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 pyin 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()
-
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 -
@i_mazlov thanks ilia!!!
ok that was truly obvious
actually had to use 'c4d.documents.GetActiveDocument()' to make it work in my case ...