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

    Print real time instead of waiting until the end

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

      I need to output a number for a loading bar within one of my plugins.

      But the issue is that python wont print until the end of a function.

      for example:

      import sys
      import time
        
      def main() :
        
          print "one"
          sys.stdout.flush()
          time.sleep(5)
          print "two"
        
      if __name__=='__main__':
          main()
      

      waits 5 seconds and then prints "one"  and "two" at the same time.

      how can a make them output realtime.

      I tried adding

      sys.stdout.flush()
      

      which would be the solution if this wasnt python within c4d.

      thanks

      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 09/08/2012 at 23:43, xxxxxxxx wrote:

        It works on R13 and 14 for me, but not on R12, I assume this is the version you are using.
        The same problem with this code:

        import sys  
        import time  
          
        def main() :  
          
          for i in xrange(10) :  
              print i  
              time.sleep(0.5)  
          
        main()
        

        The Console in R12 seems to be updated only when the Script Manager ends. Don't know for sure, but it should actually work for a plugin, except the Python Console is updating periodically.

        -Niklas

        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 09/08/2012 at 23:47, xxxxxxxx wrote:

          You can use c4d.GePrint() instead of Python standard print:

          import time
          import c4d
            
          def main() :
              c4d.GePrint("one")
              time.sleep(5)
              c4d.GePrint("two")
            
          if __name__=='__main__':
              main()
          

          c4d.GePrint() is currently undocumented but it is useful in some cases like this one.

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

            Im actually using r13, so Im not sure why it doesnt work for me but it does for you. In any event, the GePrint() function worked. So thank you both for your help!

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