Get & Set Active Camera for a specific viewport
-
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!
-
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 outdevelopers.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 reachdevelopers.maxon.net
? Please also mention the OS and browser you are using.Regarding your problem:
- The viewport marked for rendering can be retrieved with
BaseDocument.GetRenderBaseDraw
. - 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,
FerdinandCode:
"""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()
- The viewport marked for rendering can be retrieved with
-
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. -
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