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

    Access C4d Main Thread

    Scheduled Pinned Locked Moved PYTHON Development
    3 Posts 0 Posters 439 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 15/05/2017 at 08:50, xxxxxxxx wrote:

      Hi, 
      I'm new to python development into C4D.

      I am developing some pipeline tools that 'communicate' with different 3d apps (Maya, Houdini, C4D, etc.). Basically, it's an external application (python, PySide), and it does communicate with 3d apps to ask them to perform some commands. (IE: Open scene/document, Import specific file, exports file, save document etc.)

      I am using OSC modules to communicate from my PySide apps to C4D.
      https://wiki.labomedia.org/index.php/Envoyer_et_recevoir_de_l'OSC_en_python

      I am having a problem when trying to export alembic files using R18 (R18.041), while it does work fine with R17.

      I am suspecting that, when using OSC modules to perform my action, it does uses a different thread then C4D's main thread? (Is it possible, how can I test?) And with that example, it seems I cant export alembic file using different thread?
      https://developers.maxon.net/forum/topic/425/13566_r18-export-alembic-thread-error

      Basically, from withing C4D:

      print documents.SaveDocument(doc, 'C:	ext.abc', c4d.SAVEDOCUMENTFLAGS_DONTADDTORECENTLIST, 1028082)
      

      return true, and it does export and alembic file.

      While using OSC, C4D does listen to a specific commands (IE: Export ABC), I will execute the same command:

      print documents.SaveDocument(doc, 'C:	ext.abc', c4d.SAVEDOCUMENTFLAGS_DONTADDTORECENTLIST, 1028082)
      

      Will also return True, but doesn't export anything.

      Is there a way I can query the current thread that C4D uses? Can I force my execution tu uses main C4D thread?
      Does someone out there uses an other way than OSC to communicate with C4D and execute python commands?

      Does it work exporting alembic files?

      again... same codes work very well in R17, but doesnt in R18.

      thanks
      Jonathan

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

        On 15/05/2017 at 09:25, xxxxxxxx wrote:

        To know if you are the main thread take a look at https://developers.maxon.net/docs/py/2023_2/modules/c4d.threading/index.html#c4d.threading.GeIsMainThread

        But for you issue (exporting to abc) I suggest you to read this exemple.
        https://github.com/PluginCafe/cinema4d_py_sdk/blob/master/scripts/ExportAlembic.py
        I don't know about the R17 so you have to wait official answer but I know in R18.32(if I'm right) there is a bug into the alembic export, so make sure to have an updated version of c4d.

        About executeOnMainThread there is no proper solution for it. But you can easily register a MessageData plugin which has an CoreMessage function. Overide it and call it with a custom ID from your plugin.
        For more informations https://developers.maxon.net/forum/topic/9847/13260_christmas-competition-2016--executeinmainthread&PID=52613#52613

        And basicly SaveDocument can only save a .c4d file so I guess it's why it's fail (but I can be wrong for that ^^')

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

          On 16/05/2017 at 09:18, xxxxxxxx wrote:

          Hi,

          gr4ph0s once again made most of my work. Thanks!
          Just one minor correction, like shown in the linked ExportAlembic example SaveDocument() is not limited to .c4d files, but can be used to export scenes to different formats as well.

          @Jonathan: I'm terribly sorry, I didn't get back to you on the other thread. 
          I used your code from the other thread to do some tests here. I can reproduce the issue in R18. After some further investigation I can tell the problem is already known and will be fixed in a future release.
          So long the MessageData hint in third paragraph of gr4ph0s answer should definitely be a good workaround for you.

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