On 04/02/2014 at 08:14, xxxxxxxx wrote:
I was able to take what you provided and get it working with a file saved to the hard drive and read back in to create the document preview. Thank you for the direction.
I would prefer to skip the saving file part. The documentation for BaseBitmap.InitWith shows that it can be passed a string or a MemoryFileStruct. I found the example script for writing a bmp to a MFS so I incorporated that into the script but must be missing something. Im not getting any error messages but I'm not getting a preview either.
I tried sending the bmp to the picture viewer and have confirmed everything is working from the render standpoint. Any insight is appreciated.
import c4d
import os
from c4d import bitmaps, documents, storage
def WriteBitmap(bmp, format=c4d.FILTER_JPG,settings=c4d.BaseContainer()) :
mfs = storage.MemoryFileStruct()
mfs.SetMemoryWriteMode()
hf = storage.HyperFile()
if hf.Open(0, mfs, c4d.FILEOPEN_WRITE, c4d.FILEDIALOG_NONE) :
if not hf.WriteImage(bmp,format,settings) :
print "fail"
return None
hf.Close()
return mfs
d = c4d.documents.BaseDocument()
d.InsertObject(c4d.BaseObject(c4d.Ocube))
rd = d.GetActiveRenderData().GetData()
xres = int(rd[c4d.RDATA_XRES])
yres = int(rd[c4d.RDATA_YRES])
bmp = bitmaps.BaseBitmap()
bmp.Init(x=xres, y=yres, depth=24)
rd[c4d.RDATA_RENDERENGINE] = c4d.RDATA_RENDERENGINE_PREVIEWHARDWARE
res = documents.RenderDocument(d, rd, bmp, c4d.RENDERFLAGS_EXTERNAL)
mfs = WriteBitmap(bmp)
if res==c4d.RENDERRESULT_OK:
previewBmp = d.GetDocPreviewBitmap()
if not previewBmp.InitWith(mfs) :
raise StandardError, "Not working"
c4d.documents.SaveDocument(d, "filepath/file.c4d", c4d.SAVEDOCUMENTFLAGS_0, c4d.FORMAT_C4DEXPORT)