Exit Cinema 4D from Python
On 07/09/2015 at 03:09, xxxxxxxx wrote:
Hi! I want to close Cinema 4D (ideally with a specific exit code) from Python, and I'd prefer to use
an OS or C4D API function, but nothing but the system command works. What would be interesting
to be especially is why Cinema just freezes instead quitting or continuing to function properly.
sys.exit(1) # sys.exit() not allowed from embedded application os._exit(1) # Cinema freezes ctypes.windll.kernel32.ExitProcess(1) # Cinema freezes os.system('taskkill /PID %d' % os.getpid()) # That kind of works but I can't set the exit code
Tested on R16.
On 07/09/2015 at 04:25, xxxxxxxx wrote:
Have you try simple, write exit() , without os or sys... it works, c4d asks to save project or close it if saved(all should be saved, script too, if test be in script manager). shutdown itself and we even don't see it in task manager
On 07/09/2015 at 05:46, xxxxxxxx wrote:
Hm I guess I didn't wait for long enough. Using raise SystemExit() works, but the Cinema interface
gets disabled for some time before it really closes.
On 08/09/2015 at 02:56, xxxxxxxx wrote:
why not simply use the Quit-Command?
c4d.CallCommand(12104, 12104) # Quit (IDM_BEENDEN)
In C++ this could probably be combined with SetExitCode(), but I'm afraid in Python that is not available.