On 08/04/2013 at 11:46, xxxxxxxx wrote:
Hi!
RenderDocument() is not a GUI operation and it should be safe to call it from a threaded context.
However, using the RENDERFLAGS_OPEN_PICTUREVIEWER flag only works in synchronous (non-
threaded) context. You can use c4d.bitmaps.ShowBitmap() to manually show the bitmap in the
Picture Viewer. Also remove the RENDERFLAGS_CREATE_PICTUREVIEWER flag in this case,
otherwise your bitmap would be shown twice in the PV.
Even modifieng the document to be rendered is fine while rendering, since the document is copied
internally for rendering.
Note that passing the C4DThread, which is normally used by RenderDocument() to check if it should
stop rendering or continue by calling C4DThread.TestBreak(), will not work. Its a bug in the API and
you will get a System Error with "bad argument to internal function".
I can't reproduce that Cinema freezes.
import c4d
class RenderThread(c4d.threading.C4DThread) :
def __init__(self, doc, bmp, flags=c4d.RENDERFLAGS_EXTERNAL) :
super(RenderThread, self).__init__()
self.doc = doc
self.bmp = bmp
self.flags = flags
self.result = None
self._assert()
def _assert(self) :
assert self.doc and self.bmp
assert all(self.bmp.GetSize()), "Bitmap is not initialized."
def Main(self) :
self._assert()
w, h = self.bmp.GetSize()
rdata = self.doc.GetActiveRenderData()
rdata = rdata.GetClone(c4d.COPYFLAGS_NO_HIERARCHY)
rdata[c4d.RDATA_XRES] = w
rdata[c4d.RDATA_YRES] = h
rdata[c4d.RDATA_SAVEIMAGE] = False
self.result = c4d.documents.RenderDocument(
doc, rdata.GetData(), self.bmp, self.flags)
def main() :
bmp = c4d.bitmaps.BaseBitmap()
bmp.Init(600, 300, 32)
thread = RenderThread(doc, bmp)
thread.Start()
thread.Wait(False)
print thread.result == c4d.RENDERRESULT_OK
c4d.bitmaps.ShowBitmap(bmp)
main()