Maxon Developers Maxon Developers
    • Documentation
      • Cinema 4D Python API
      • Cinema 4D C++ API
      • Cineware 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
    1. Maxon Developers Forum
    2. Артём
    А
    • Profile
    • Following 0
    • Followers 1
    • Topics 4
    • Posts 8
    • Best 0
    • Controversial 0
    • Groups 0

    Артём

    @Артём

    0
    Reputation
    8
    Profile views
    8
    Posts
    1
    Followers
    0
    Following
    Joined Last Online

    Артём Unfollow Follow

    Latest posts made by Артём

    • How to break render thread and get the result without state bar ?

      My test environment:
      Cinema 4D version: CINEMA 4D R19.068
      Renderer: Octane renderer 3.07 R2

      This is my code:

      # -*- coding: UTF-8 -*-
      import c4d
      from time import sleep
      
      
      # Save path
      save_path = "D:\\temp"  # It's my dir for test. Change it if you dont want to save your bmp at here.
      
      
      class RenderThread(c4d.threading.C4DThread):
          global save_path
          
          # Override
          def __init__(self, doc, rd, bmp):
              self.break_flag = False
              self.doc = doc
              self.rd = rd
              self.bmp = bmp
              self.res = None
              
          # Override
          def Main(self):
              self.res = c4d.documents.RenderDocument(
                  self.doc,
                  self.rd,
                  self.bmp,
                  c4d.RENDERFLAGS_EXTERNAL
              )
              
              # Just a test for distinguish the result file is saved by which thread.
              # If i get this file, it indicates that the render thread has run completed.
              if self.res == c4d.RENDERRESULT_OK:
                  self.bmp.Save(
                      "{}\\RenderThread_SaveResult.jpg".format(save_path),
                      c4d.FILTER_JPG
                  )
      
          # Override
          def TestDBreak(self):
              return self.break_flag
      
      
      # This method is main thread.
      def main():
          global save_path
          
          doc = c4d.documents.GetActiveDocument()
          rd = doc.GetActiveRenderData().GetData()
          bmp = c4d.bitmaps.BaseBitmap()
          bmp.Init(rd[c4d.RDATA_XRES], rd[c4d.RDATA_YRES])
          
          th = RenderThread(doc, rd ,bmp)
          th.Start()
      
          count = 0  # When "count" equals 10, end render thread.
          while True:
              print "Current count ->", count
      
              # Show bmp to picture viewer
              c4d.CallCommand(430000740, 430000740) # Remove All Images --> Clear history, just show current bmp
              c4d.CallCommand(430000774, 430000774) # Auto Zoom Mode --> Zoom picture to fit the picture viewer
              c4d.bitmaps.ShowBitmap(bmp)
      
              # Listen for the running state of the render thread.
              is_run = th.IsRunning()
              print "Is render thread running ->", is_run
              
              if not is_run:
                  print "End Render Thread"
                  
                  # If i get this file, it indicates that the render thread has run completed.
                  if th.res == c4d.RENDERRESULT_OK:
                      th.bmp.Save(
                          "{}\\MainThread_SaveResult.jpg".format(save_path),
                          c4d.FILTER_JPG
                      )
                  
                  break
      
              # Test of break render thread
              if count == 10:
                  print "Break Render Thread"
      
                  th.break_flag = True
                  break_res = th.TestBreak()
      
                  print "TestBreak() result ->", break_res
      
                  if break_res:
                      th.End(False)  # It doesn't work... and the bottom of result image have a state bar... 
                      print "Execute End()..."
                  
                  print "Is render thread still running ->", th.IsRunning()
                  
                  # If i get this file, it indicates that the render thread has break.
                  th.bmp.Save(
                      "{}\\Break_SaveResult.jpg".format(save_path),
                      c4d.FILTER_JPG
                  )
      
                  break
      
              count += 1
              sleep(1)
      
      
      if __name__ == "__main__":
          c4d.CallCommand(13957) # Clear Console
          main()
      

      There has two questions:

      1. In fact, render thread is not break... this is my c4d console log:
        After "End()" has executed, render thread is still running...
        Emmmm... how to really end render thread ?

      log.jpg

      1. I got a image after "End()", but the image has a state bar at bottom...
        So, can I get the image without state bar when I break render thread ?
        This is the image:

      Break_SaveResult.jpg

      Finally, I will got two images, because render thread doesn't break:
      results.jpg

      posted in Cinema 4D SDK python r19
      А
      Артём
    • RE: How to control Picture Viewer by Python in C4D R19 ?

      @m_magalhaes
      Thanks you very much !
      It's very help !

      posted in Cinema 4D SDK
      А
      Артём
    • How to control Picture Viewer by Python in C4D R19 ?

      How to control Picture Viewer by Python in C4D R19 ?

      Such as "Stop Rendering" , "Save Image", "Clear History"......

      I can't find useful info in python doc...

      posted in Cinema 4D SDK
      А
      Артём
    • RE: How to get renderer version number by python in C4D R19 ?

      @m_adam Thank you for your advice.

      posted in Cinema 4D SDK
      А
      Артём
    • How to get renderer version number by python in C4D R19 ?

      If my renderer is Octane Render 3.07 R2
      For example:

      # -*- coding: utf-8 -*-
      import c4d
      
      def test():
          doc = c4d.documents.GetActiveDocument()
          rd = doc.GetActiveRenderData()
      
          current_renderer_id = rd[c4d.RDATA_RENDERENGINE]
          current_renderer_name = c4d.documents.BaseVideoPost(current_renderer_id ).GetName()\
              if currentRendererID else "Standard"
          
          print "Current Renderer ID:", current_renderer_id  # 1029525
          print "Current Renderer Name:", current_renderer_name  # Octane Render
      
      if __name__ == "__main__":
          test()
      

      Emmmmm......
      So, I can get id and name about octane renderer, but how to get version number by python ?

      posted in Cinema 4D SDK
      А
      Артём
    • RE: How to get a realpath of asset in c4d R19 by python ?

      Thanks !
      It works !
      🙂

      posted in Cinema 4D SDK
      А
      Артём
    • How to get a realpath of asset in c4d R19 by python ?

      I tried "GetAllAssets()" and "GetAllTextures()", but I can't get realpath...

      this is my test code:

      # -*- coding: utf-8 -*-
      """
      该模块用于解析场景使用,
      无论插件提交,还是客户端提交,
      解析方面的工作都在这个模块实现
      """
      import c4d
      
      
      class Parse:
          # Override
          def __init__(self, doc):
              """
              parameters::
                  doc ==> 当前C4D场景
              """
              self.doc = doc
      
          def assetParse(self):
              """
              资源解析,解析场景中所有资源,
              是否存在,路径等信息
              """
              assets = c4d.documents.GetAllAssets(self.doc, False, "")
              if not assets:
                  assets = self.doc.GetAllTextures()
              
              self.assets = assets
          
          def test(self):
              self.doc.SendInfo(
                  c4d.MSG_DOCUMENTINFO_TYPE_MAKEPROJECT,
                  c4d.FORMAT_C4DEXPORT,
                  self.doc.GetDocumentName()
              )
          
      
      if __name__ == "__main__":
          c4d.CallCommand(13957) # Clear Console
          
          doc = c4d.documents.GetActiveDocument()
          doc_parsed = Parse(doc)
          doc_parsed.assetParse()
          
          # for i in doc_parsed.assets[0]:
          #     print i
              
          for i in doc_parsed.assets:
              print i
      
      posted in Cinema 4D SDK
      А
      Артём