Solved Take Viewport Screenshot


Is there a way to take a viewport screenshot (i.e. exactly what the viewport is displayed)?
I have a WIP code but it uses a camera independent of the current camera the viewport is looking at:

You can also check the illustration of the problem here:

def main():
    bmp = doc.GetDocPreviewBitmap()

Thank you for looking at my problem


just FYI: GetDocPreviewBitmap() returns the image that is stored in the c4d file and that is used as a thumbnail image. It is created when the scene is saved; it has nothing to do with the current viewport image.

You have to make render with Software Renderer.

Checkout my python tutorials, plugins, scripts, xpresso presets and more

There's also the "Send to Picture Viewer" command (by default in viewport View menu), command ID is 300001097, which would fit your purpose quite well...
Unfortunately it has some downsides, when trying to use it from code instead of from the UI.

  • With multiple viewports you lack an option to choose the viewport, instead the active one will be taken.
  • With multiple viewports there's a bug, which sometimes leads to a black image.


Edit: Forget it, playing around with it, I think it is broken for every other than the first viewport (regardless of code or UI). Sorry.


as @mikeudin said you have to render the document using Software renderer.
Change the render setting to software/hardware renderer, use RenderDocument and retrieve the result.
After that, change back the render engine to what it was.

import c4d
from c4d import gui

# Main function
def main():
     # Retrieves the current active render settings
    rd = doc.GetActiveRenderData()
    saved = rd[c4d.RDATA_RENDERENGINE] 
    # Creates a Multi Pass Bitmaps that will store the render result
    bmp = c4d.bitmaps.MultipassBitmap(int(rd[c4d.RDATA_XRES]), int(rd[c4d.RDATA_YRES]), c4d.COLORMODE_RGB)
    if bmp is None:
        raise RuntimeError("Failed to create the bitmap.")

    # Adds an alpha channel
    bmp.AddChannel(True, True)

    # Renders the document
    if c4d.documents.RenderDocument(doc, rd.GetData(), bmp, c4d.RENDERFLAGS_EXTERNAL) != c4d.RENDERRESULT_OK:
        raise RuntimeError("Failed to render the temporary document.")

    # Displays the render in the Picture Viewer

    rd[c4d.RDATA_RENDERENGINE] = saved

if __name__ == "__main__":


MAXON SDK Specialist

MAXON Registered Developer

Thank you all for the response. Appreciate a lot.

Specially for the sample code provided by @m_magalhaes as this is my code relating to rendering.