Hey,
I am trying to code a python script that automatically renders the active document and sets the preview for the document to that rendered image.
The set parameter that I use wants a BaseList2D object instead of a bitmap and I have no idea how I could convert that info. (Or maybe im dead lost already ) Maybe you can help?
Thanks in advance
import c4d
from c4d import documents
import os
def main():
doc = documents.GetActiveDocument()
rd = doc.GetActiveRenderData()
# Set resolution
rd[c4d.RDATA_XRES] = 640
rd[c4d.RDATA_YRES] = 480
# Render document
bmp = c4d.bitmaps.BaseBitmap()
bmp.Init(640, 480)
if c4d.documents.RenderDocument(doc, rd.GetDataInstance(), bmp, c4d.RENDERFLAGS_EXTERNAL) != c4d.RENDERRESULT_OK:
raise Exception("Rendering failed")
# Save bitmap to disk for manual setting of preview later
temp_filepath = os.path.join(os.path.expanduser("~"), "temp_preview.png")
if bmp.Save(temp_filepath, c4d.FILTER_PNG, c4d.BaseContainer()) != c4d.IMAGERESULT_OK:
raise Exception("Failed to save bitmap")
# Display the bitmap for verification
c4d.bitmaps.ShowBitmap(bmp)
# Set the rendered Bitmap bmp as the preview of the document
doc.SetParameter(c4d.DOCUMENT_PREVIEW_IMAGE, bmp, c4d.DESCFLAGS_SET_0) #<--- cant figure out how to get this working
if __name__ == '__main__':
main()
Version: Cinema4D 2025.0.2
OS: Windows 11
Python