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
    • Recent
    • Tags
    • Users
    • Login

    Exit Cinema 4D from Python

    Scheduled Pinned Locked Moved PYTHON Development
    4 Posts 0 Posters 394 Views
    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.
    • H Offline
      Helper
      last edited by

      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.

      1 Reply Last reply Reply Quote 0
      • H Offline
        Helper
        last edited by

        On 07/09/2015 at 04:25, xxxxxxxx wrote:

        Hi
        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

        1 Reply Last reply Reply Quote 0
        • H Offline
          Helper
          last edited by

          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.

          Thanks Ilya

          1 Reply Last reply Reply Quote 0
          • H Offline
            Helper
            last edited by

            On 08/09/2015 at 02:56, xxxxxxxx wrote:

            Hi Niklas,

            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.

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