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

    Watch Folder

    Scheduled Pinned Locked Moved PYTHON Development
    2 Posts 0 Posters 223 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 13/08/2012 at 02:09, xxxxxxxx wrote:

      Hey all,

      I'm trying to write a script that watches a folder and looks for new C4D files. Once it finds a new file it should add the file to the render que. The code works fine in an external editor, however in C4D it doesn't work. When I run the script and add a new file to the watch folder, C4D hangs and I have to restart it.

      Does anyone have a clue why? See the code below.

      Greets,
      Hans Willem

      import c4d
      import os
      import time

      def watchFolder() :
          before = os.listdir('/Users/blabla/watch folder')
          while 1:
              global newFiles
              time.sleep(3)
              after = os.listdir('/Users/blabla/watch folder')
              newFiles = list(set(after)-set(before))
              if len(newFiles) > 0:
                  renderFile()
                  break
                  before = after

      def renderFile() :
          for i in newFiles:
              if i[-3:] =='c4d':
                  # then some code here to add the file to the renderque and start rendering
          watchFolder()

      watchFolder()

      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 13/08/2012 at 03:27, xxxxxxxx wrote:

        Of course it hangs, because you block the main thread. Put your code into a threaded environment. 🙂
        For R13+, see the c4d.threading module which works afaik fine in the Script Manager. For R12, you'd need to write a plugin that uses the built-in threading module.

        -Nik

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