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

    detect that c4d is running

    Scheduled Pinned Locked Moved PYTHON Development
    6 Posts 0 Posters 628 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/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.

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

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

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

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

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

          exp.

            
             while True:
                                        
                          if self.TestBreak() :
                              c4d.StopAllThreads()
                              break
            
          
          
          1 Reply Last reply Reply Quote 0
          • H Offline
            Helper
            last edited by

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

            https://developers.maxon.net/forum/topic/9808/13204_what-exactly-does-stopallthreads-do&PID=52236#52236

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

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

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

              ❤
               if self.TestBreak() :
                         
                                  self.End()

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

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

                Hi,

                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())

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