Hello @JACK0319 ,
I'm not sure what you consider the "correct result", but it looks good here:
9888272b-b870-4514-80e9-e16f01e6dc14-image.png
However, there're a couple things to mention about your script.
First, there SendModelingCommand() function executes passes itself, so there's no need in munally running ExecutePasses() function.
Second, in the last line you insert the result object from the CSTO command into document stored in doc variable. At this point doc still points to the document that was active before you executed function InsertBaseDocument(). After this function call, GetActiveDocument() returns the same document that you have in temp_doc. However, there's one edge case, which happens if you execute InsertBaseDocument() function while currently active document is empty. In this case, current document is deallocated and doc points to the invalid document. This is why you see the corresponding log in python console:
ReferenceError: the object 'c4d.documents.BaseDocument' is not alive
By the way, this is similar behavior you notice when clicking on [+] button 0dd7ae71-413a-4cf6-b981-b42ca06e488b-image.png multiple times: it kills currently active empty document and activates new empty document instead.
There're multiple solutions for you depending on what are your intentions with this script:
If you only need baked object inserted to currently active document, there's no need in attaching your temporary document to cinema with the InsertBaseDocument() function
If otherwise you need the temporary document to be inserted to cinema, consider attaching it after you insert cache to the old document.
If you're attaching temp_doc to cinema only for debugging purposes, you can early exit your script to not let it go to the insertion step. Another option could be to "touch" original document (e.g. by inserting c4d.Onull object at the beginning of the script and removing it in the end).
Cheers,
Ilia