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

    execute on main thread

    Scheduled Pinned Locked Moved PYTHON Development
    6 Posts 0 Posters 822 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 05/12/2016 at 13:37, xxxxxxxx wrote:

      Hi, I'm looking for a way to execute functions on the main thread from a different thread. I have found c4d.SpecialEventAdd, but it seems very limited. To pass custom parameters, it only allows for p1 and p2, which are both integers. How can I pass a string? Also, how do I get these parameters in the main thread?When I use MessageData.CoreMessage to handle the event, the bc parameter contains c4d.DA_VOID values which are PyCObjects. What am I supposed to do with these?
      Any help is appreciated.

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

        On 06/12/2016 at 02:28, xxxxxxxx wrote:

        Hi,

        welcome to the Plugin Café forums 🙂

        This question has been discussed several times in these forum.

        A explanation how to receive the parameters in CoreMessage can be found in the How to identify different calls to CoreMessage? thread (see Yannick's answer). Also in SpecialEventAdd data thread.
        A workaround to transfer float values (while losing precision) can be found in the SpecialEventAdd and Float parameter thread.

        In order to transfer more complex data, we suggest to use some kind of global storage (in simplest form just a global variable). Store the data there before calling SpecialEventAdd() and then consume the data in CoreMessage(), possibly using the two integer parameters to identify the data.

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

          On 06/12/2016 at 07:25, xxxxxxxx wrote:

          Thank you Andreas,
          I'll go with the global variable solution.

          What's the best place to put in a feature request? The thing is, in almost every software I've used it's been so much easier to execute a function in the main thread. Maya, Nuke, and Houdini all have a function called executeInMainThreadWithResult which is so much simpler to use. PySide (Qt) as well has a really simple way to call a function in the main thread by using Signals and Slots. It would be great to have this in Cinema 4D without having to deal with PyCObjects and allowing to pass more complex data types than integers.

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

            On 07/12/2016 at 02:17, xxxxxxxx wrote:

            Actually you are at the best place you can be for any SDK related feature requests.
            It is noted down.
            Just want to add, that this is not in any case specific to our Python SDK, but it works the same in the C++ SDK (with the exception, that it's easy in C++ to mis-use the integer parameters as pointers to pass arbitrary information).
            It shouldn't be too complicated to write a "ExecuteInMainThread" functionality yourself, even in Python. Maybe I find time during Christmas vacation. But maybe we can even make it a small Christmas contest? I have set up a thread for this here.

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

              On 07/12/2016 at 07:04, xxxxxxxx wrote:

              Thanks Andreas.
              I was able to get an executeInMainThreadWithResult function working. I mostly copied Houdini's hdefereval module, so I don't know if it's okay to post it.

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

                On 07/12/2016 at 07:34, xxxxxxxx wrote:

                I'd rather not post code, which intellectual property is not clear.

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