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

    Get & Set Active Camera for a specific viewport

    Cinema 4D SDK
    python
    2
    4
    992
    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
      Thodos
      last edited by

      Hi!
      While the Python manual is offline and I don't have an offline version:
      I found on the forum how to find which viewport is used for render view, but it looks a bit too much.
      Maybe there is a way on how to Get and Set Active camera only for a viewport that is used by Render View?

      Cheers!

      ferdinandF 1 Reply Last reply Reply Quote 0
      • ferdinandF
        ferdinand @Thodos
        last edited by ferdinand

        Hey @Thodos,

        Thank you for reaching out to us. The Python manuals are not offline, developers.maxon.net is up and running, and I can reach it. We are, however, in the middle of phasing out developers.maxon.net, so I am also not surprised that something is going wrong for some people. Would it be possible that you to share your console log for when you are trying to reach developers.maxon.net? Please also mention the OS and browser you are using.

        Regarding your problem:

        1. The viewport marked for rendering can be retrieved with BaseDocument.GetRenderBaseDraw.
        2. There can be up two cameras associated with each BaseView\BaseDraw, the default internal one, and a user provided one. For details, please see my code example below.

        Cheers,
        Ferdinand

        Code:

        """Demonstrates how to get and set the camera of the render view of a document.
        
        Must be run as a Script Manager script. Will modify the active render camera and then replace it
        with a new camera.
        """
        
        import c4d
        
        doc: c4d.documents.BaseDocument  # The active document
        
        def main() -> None:
            """Runs the example.
            """
            # Get the 'BaseDraw' a.k.a. viewport that is used for rendering from the active document.
            viewport: c4d.BaseDraw = doc.GetRenderBaseDraw()
            if not viewport:
                raise RuntimeError("Could not access rendering view port.")
        
            # All view ports can have two cameras, an internal one which always exists, and a user defined
            # one which only exists when a user has crated and linked a camera object. We must sort out
            # this situation here by falling back to the editor camera when there is no scene camera.
            camera: c4d.BaseObject = viewport.GetSceneCamera(doc) or viewport.GetEditorCamera()
            if not camera:
                raise RuntimeError("Could not access render camera.")
            
            # Modify the camera transform.
            camera.SetMg(
                c4d.utils.MatrixMove(c4d.Vector(200, 100, -500)) *
                c4d.utils.MatrixRotY(c4d.utils.DegToRad(45)) *
                c4d.utils.MatrixRotZ(c4d.utils.DegToRad(15))
            )
        
            # When we want to link a new camera, we must use parameter access via BASEDRAW_DATA_CAMERA to
            # link it in the BaseView/BaseDraw.
            newCamera: c4d.BaseObject = c4d.BaseObject(c4d.Orscamera)
            if not newCamera:
                raise MemoryError("Could not instantiate new camera.")
            doc.InsertObject(newCamera)
        
            newCamera.SetMg(
                c4d.utils.MatrixMove(c4d.Vector(-400, 500, 1000)) *
                c4d.utils.MatrixRotY(c4d.utils.DegToRad(-30)) *
                c4d.utils.MatrixRotX(c4d.utils.DegToRad(30))
            )
                
            viewport[c4d.BASEDRAW_DATA_CAMERA] = newCamera
            c4d.EventAdd()
        
        
        if __name__ == '__main__':
            main()
        

        MAXON SDK Specialist
        developers.maxon.net

        1 Reply Last reply Reply Quote 0
        • T
          Thodos
          last edited by

          Hey @ferdinand ,
          Thank you so much for the response!
          You are a real saviour!

          Unfortunately, I tried both Windows and iOS using Ukrainian and Turkey ethernet(not VPN) but still had no luck with developers.maxon.net

          Cheers,
          Max.

          ferdinandF 1 Reply Last reply Reply Quote 0
          • ferdinandF
            ferdinand @Thodos
            last edited by

            Hey @Thodos,

            without the console output of your browser, I cannot say much. I suspect that a DNS is failing.

            In the meantime, here are the offline docs.

            Cheers,
            Ferdinand

            MAXON SDK Specialist
            developers.maxon.net

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