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

    any way to close cinema 4d from the python script

    Cinema 4D SDK
    4
    4
    833
    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.
    • W
      wob
      last edited by m_adam

      is there any way to close cinema 4d app from the python script? i foundrestart cinema 4d command only in python sdk but what's about quit / exit command? is it possible?

      i need it to free RAM after exporting scene in standalone render via python script.

      thanks.

      1 Reply Last reply Reply Quote 0
      • ferdinandF
        ferdinand
        last edited by ferdinand

        Hi again ;),

        what do you mean by "python script" here, a Script manager script or c4dpy?

        For the latter you can use os.execl, which will run whatever you are passing to it in a new interpreter. There are many threads on this topic on stack-overflow, but there is no sane way to ensure that the first interpreter actually closes while second one runs. An easier solution would be to just stack two scripts in your os-dependent script language (i.e. a batch file in Windows).

        If you want to close the GUI-app, I am afraid there is no command for that because of the security implications (how to handle unsaved content?), you could wiggle your way around it by getting the handle of the Cinema window, but the problem on how to handle unsaved content would remain.

        If it is only garbage collection you are after, you could also use Python's gc module to halt your script until the garbage collector thinks it is done. But Cinema is sort of a special case due to the way its API is constructed, which can cause stuff to linger for quite a while, even if when you think you have removed all references.

        Cheers,
        zipit

        MAXON SDK Specialist
        developers.maxon.net

        1 Reply Last reply Reply Quote 0
        • CairynC
          Cairyn
          last edited by

          I was curious and just tried c4d.CallCommand(12104) - it does close the GUI app even from a Python script. (And asks for unsaved content too; I suppose it won't close if you cancel but I didn't check that.)

          1 Reply Last reply Reply Quote 0
          • M
            m_adam
            last edited by

            Hi @wob there is noting built-in for that in Cinema 4D. but you can use the regular python way to kill the current process

            import signal
            import os
            
            os.kill(os.getpid(), signal.SIGTERM)
            

            But I just let you know, that it may be useless by nature python should be pretty good at not creating any memory leak, and should free the data as soon as possible, moreover your approach ( I don't know the whole pipeline) but may also be a big issue for a user since this will clause Cinema 4D without asking for saving. People may lose their work. So I really encourage you to be very careful with the use of this.

            Cheers,
            Maxime.

            MAXON SDK Specialist

            Development Blog, MAXON Registered Developer

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