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

    How to use Python to implement rendering with Octane in C4D and export as PNG

    General Talk
    python
    3
    6
    1.3k
    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.
    • T
      tx3008
      last edited by

      How to use Python to implement rendering with Octane in C4D and export as PNG

      DunhouD i_mazlovI 2 Replies Last reply Reply Quote 0
      • DunhouD
        Dunhou @tx3008
        last edited by

        Hey @tx3008 ,

        You need check the Octane BaseVideoPost to get the data container.

        You can change the render settings and use RenderDocument to render images.

        In case if you didn't want to use my extra libs, the GetVideoPost is not complicated.

        Cheer~
        DunHou

        # 获取渲染器VideoPost
        def GetVideoPost(document: c4d.documents.BaseDocument = None, videopost: int = ID_REDSHIFT) -> Optional[c4d.documents.BaseVideoPost]:
            """
            Get the videopost of given render engine of filled document.
        
            Args:
                document (c4d.documents.BaseDocument, optional): Fill None to check active documents. Defaults to None.
                videopost (int, optional): The id of the videopost. Defaults to ID_REDSHIFT.
        
            Returns:
                Optional[c4d.documents.BaseVideoPost]: The videopost we get.
            """
            if not document:
                document = c4d.documents.GetActiveDocument()
        
            rdata: c4d.documents.RenderData = document.GetActiveRenderData()
            vpost: c4d.documents.BaseVideoPost = rdata.GetFirstVideoPost()
            theVp: c4d.documents.BaseVideoPost = None
        
            while vpost:
                if vpost.GetType() == int(videopost):
                    theVp = vpost
                vpost = vpost.GetNext()
            return theVp
        
        import c4d
        import Renderer
        
        def main():
        
            OctaneRenderer = Renderer.GetVideoPost(c4d.documents.GetActiveDocument(),
                                                   Renderer.ID_OCTANE)
        
            OctaneRenderer[c4d.SET_PASSES_FILEFORMAT] = 10 # Octane PNG, 6 = PNG
            OctaneRenderer[c4d.SET_PASSES_SAVE_MAINPASS] = True
            OctaneRenderer[c4d.SET_PASSES_ENABLED] = True
            OctaneRenderer[c4d.SET_PASSES_SAVEPATH] = "Render/$prj/$prj"
        
            c4d.EventAdd()
        
        if __name__=='__main__':
            main()
        
        

        https://boghma.com
        https://github.com/DunHouGo

        T 1 Reply Last reply Reply Quote 1
        • T
          tx3008 @Dunhou
          last edited by tx3008

          @Dunhou
          Thank you very much for answering my questions. I saw your library yesterday and tried to write like this

          from typing import Optional
          import c4d
          
          
          ID_OCTANE: int = 1029525 # Octane 
          ID_REDSHIFT: int = 1036219 # Redshift
          ID_ARNOLD: int = 1029988 # Arnold
          ID_VRAY: int = 1053272
          ID_CORONA: int = 1030480
          ID_LOOKS: int = 1054755
          ID_CENTILEO: int = 1036821
          ID_OCTANE_VIDEO_POST = 1029525 # octane render
          file_path="C:/Users/admin/Documents/WXWork/1688858265477290/Cache/File/2024-09/OC_light/11.png"
          
          doc: c4d.documents.BaseDocument  # The active document
          op: Optional[c4d.BaseObject]  # The active object, None if unselected
          
          def GetVideoPost(document: c4d.documents.BaseDocument = None, videopost: int = ID_REDSHIFT) -> Optional[c4d.documents.BaseVideoPost]:
              """
              Get the videopost of given render engine of filled document.
          
              Args:
                  document (c4d.documents.BaseDocument, optional): Fill None to check active documents. Defaults to None.
                  videopost (int, optional): The id of the videopost. Defaults to ID_REDSHIFT.
          
              Returns:
                  Optional[c4d.documents.BaseVideoPost]: The videopost we get.
              """
              if not document:
                  document = c4d.documents.GetActiveDocument()
          
              rdata: c4d.documents.RenderData = document.GetActiveRenderData()
              vpost: c4d.documents.BaseVideoPost = rdata.GetFirstVideoPost()
              theVp: c4d.documents.BaseVideoPost = None
          
              while vpost:
                  print(vpost.GetType())
                  if vpost.GetType() == int(ID_OCTANE_VIDEO_POST):
                      theVp = vpost
                  vpost = vpost.GetNext()
              return theVp
          def main():
          
              OctaneRenderer = GetVideoPost(c4d.documents.GetActiveDocument(),ID_OCTANE)
          
              OctaneRenderer[c4d.SET_PASSES_FILEFORMAT] = 6 # Octane PNG, 6 = PNG
              OctaneRenderer[c4d.SET_PASSES_SAVE_MAINPASS] = True
              OctaneRenderer[c4d.SET_PASSES_ENABLED] = True
              OctaneRenderer[c4d.SET_PASSES_SAVEPATH] = file_path
          
              c4d.EventAdd()
          
          if __name__=='__main__':
              main()
          

          But there are no images generated in the directory. What could be the reason?

          DunhouD 1 Reply Last reply Reply Quote 0
          • DunhouD
            Dunhou @tx3008
            last edited by

            @tx3008 You just modify the rd but not rendering anythings.

            https://boghma.com
            https://github.com/DunHouGo

            T 1 Reply Last reply Reply Quote 0
            • T
              tx3008 @Dunhou
              last edited by

              @Dunhou I understand now. I have tried it successfully. Thank you very much!

              1 Reply Last reply Reply Quote 0
              • i_mazlovI
                i_mazlov @tx3008
                last edited by

                Hi @tx3008,

                Welcome to the Maxon developers forum and its community, it is great to have you with us!

                Getting Started

                Before creating your next postings, we would recommend making yourself accustomed with our forum and support procedures. You did not do anything wrong, we point all new users to these rules.

                • Forum Overview: Provides a broad overview of the fundamental structure and rules of this forum, such as the purpose of the different sub-forums or the fact that we will ban users who engage in hate speech or harassment.
                • Support Procedures: Provides a more in detail overview of how we provide technical support for APIs here. This topic will tell you how to ask good questions and limits of our technical support.
                • Forum Features: Provides an overview of the technical features of this forum, such as Markdown markup or file uploads.

                It is strongly recommended to read the first two topics carefully, especially the section Support Procedures: Asking Questions.

                About your First Question

                Third party software is out of scope of our Support Procedures, namely:

                We cannot provide support for third party libraries.

                Hence I've moved your thread to the "General Talk" forum.

                Many thanks to @Dunhou for taking an active role of our community! Much appreciated!

                Cheers,
                Ilia

                MAXON SDK Specialist
                developers.maxon.net

                1 Reply Last reply Reply Quote 0
                • i_mazlovI i_mazlov moved this topic from Cinema 4D SDK on
                • First post
                  Last post