detect that c4d is running

  • On 07/03/2017 at 08:56, xxxxxxxx wrote:

    i got a script which starts a thread in the background using c4d.threading.C4DThread.

    if i close my c4d application the thread stays active and c4d do not close completly ( taskmanager > cinema4d.exe )

    i try to use C4DThread.TestBreak() but i guess that might be the wrong way to do this.

  • On 07/03/2017 at 09:05, xxxxxxxx wrote:

    TestBreak and TestDBreak just return a state you have to quit your thread manually.

  • On 07/03/2017 at 09:22, xxxxxxxx wrote:


       while True:
                    if self.TestBreak() :

  • On 07/03/2017 at 09:33, xxxxxxxx wrote:

    Normally you don't need to call StopAllThread.
    Morre safe could be to make a return instead of break or even do

  • On 07/03/2017 at 10:09, xxxxxxxx wrote:

     if self.TestBreak() :

  • On 08/03/2017 at 02:37, xxxxxxxx wrote:


    I'm not sure, if you try to use a thread from a Python script (in the following I use the term script only for code called from the Script Manager) or from a Python plugin (like CommandData).

    In general it's not a good idea to create a thread from inside a script. The thing is, who owns the thread after the script is finished. Even if using a global variable, we have nowhere documented, what happens to global variables after a script finished (for good reason). So the behavior is already undocumented. But what happens, if the script is run for a second time. If not before, at least at this point, nobody will be storing a reference to this thread anymore, as the script will overwrite the globals.

    The better way to do something like this, is to implement a CommandData plugin (other types might work as well, depending on your needs and actual use-case). There you have a "resident" class, which can host the thread (i.E. store a reference to the thread in a member variable). And then you can also implement PluginMessage() in order to react to Cinema quitting.

    Just for completeness for future readers:
    In Python docs: Threading, BaseThread
    In C++ docs there are manuals on different areas of threading and Plugin Functions (like PluginMessage())

Log in to reply