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:
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.
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.
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.
from c4d import gui
# Main function
# Retrieves the current active render settings
rd = doc.GetActiveRenderData()
saved = rd[c4d.RDATA_RENDERENGINE]
rd[c4d.RDATA_RENDERENGINE] = c4d.RDATA_RENDERENGINE_PREVIEWHARDWARE
# 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
# 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__":
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.