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

    Call function from main thread

    Scheduled Pinned Locked Moved PYTHON Development
    8 Posts 0 Posters 1.6k 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

      THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

      On 12/04/2011 at 10:07, xxxxxxxx wrote:

      Hello,

      the python documentation states for DrawViews(...) :
      "Redraws the editor views. Must be called from the main thread!"

      So, how do I control which thread is calling my Python Node (or how to know which thread is calling)?
      When I try to call the "add" button within the Mograph-Multishader by python:

      multishader = material[c4d.MATERIAL_COLOR_SHADER];  
      c4d.CallButton(multishader, 1002) #MGMULTISHADER_ADD = 1002,
      

      I get the error:
      RuntimeError: Illegal operation. Invalid cross-thread call.

      This happens from a Python Node within XPresso.
      How can I prevent/control that ?

      Thank you,
      maxx

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

        THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

        On 12/04/2011 at 12:14, xxxxxxxx wrote:

        This is not documentated for nodes yet. The hooks for Python in the Python Generator, Python Tag and Python Node are called in a threaded context. Within this hooks you should never call GUI stuff or change the document hierarchy. Methods which are called in a threaded context are documentated with this note:

        Important: This function is called in a thread context.
        _
        _
        What exactly do you want to achieve? Maybe there is a workaround for this.

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

          THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

          On 12/04/2011 at 14:23, xxxxxxxx wrote:

          Hy there,

          my goal is to automate the loading of Bitmap-Shaders into the MoGraph multi-shader.

          I already tried to insert the shader directly to the multishader:

          shn = c4d.BaseList2D(c4d.Xbitmap)
           
          mat[c4d.MATERIAL_COLOR_SHADER] = shn
          material.InsertShader(shn,sh)
          material.Message(c4d.MSG_UPDATE)
          material.Update(True,True)
          c4d.EventAdd()

          But this will not work. Actually, the shader is in the (internal) list, but it won't show up in the multi-shader and also has no effect.

          So I tried to use the "Add" button, to add the shaders. Yea, desperate measures 😉

          Is it then possible to add a hook from within a Python Node which gets called by the main-thread?

          Can you give me an example, how to use that CallButton(..) function in the right context ?

          Thank you,
          maxx

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

            THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

            On 01/06/2011 at 09:35, xxxxxxxx wrote:

            Sorry for the late reply. I will check out if I can provide you with an example.

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

              THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

              On 02/06/2011 at 08:26, xxxxxxxx wrote:

              .. that would be nice, thank you

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

                On 21/04/2014 at 13:36, xxxxxxxx wrote:

                curious if you ever found a solution. Running into this now too. Seems kind of silly we can't call a button in a pynode

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

                  On 02/05/2014 at 06:27, xxxxxxxx wrote:

                  It's by design. A button could do things that you really don't want to happen from an Expression.
                  Use c4d.SpecialEventAdd() and listen to it with a MessageData plugin. That's one of the work arounds,
                  but it's not possible without coding a real plugin.

                  -Niklas

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

                    On 02/05/2014 at 16:06, xxxxxxxx wrote:

                    Dang! I'll look into the SpecialEventAdd. Thanks Niklas.

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