On 08/04/2013 at 07:49, xxxxxxxx wrote:
Hi everyone!
I want to render a picture using a thread, so C4D isn't freezing during rendering. I use a CommandData plugin and the c4dThread module. Here's my thread code:
import c4d
from c4d import documents
from c4d.threading import C4DThread
class RenderThread(C4DThread) :
def __init__(self, doc) :
super(RenderThread, self).__init__()
self.doc = doc
def Main(self) :
renderData = self.doc.GetActiveRenderData()
xResolution = int(round(renderData[c4d.RDATA_XRES]))
yResolution = int(round(renderData[c4d.RDATA_YRES]))
renderBmp = c4d.bitmaps.BaseBitmap()
renderBmp.Init(x=xResolution, y=yResolution, depth=32, flags=c4d.INITBITMAPFLAGS_0)
result = documents.RenderDocument(self.doc, renderData.GetData(), renderBmp, c4d.RENDERFLAGS_EXTERNAL | c4d.RENDERFLAGS_CREATE_PICTUREVIEWER | c4d.RENDERFLAGS_OPEN_PICTUREVIEWER)
print result
This is the call:
class CommandDataExecute(plugins.CommandData) :
__dialog = None
renderThread = None
def Execute(self, doc) :
doc = documents.GetActiveDocument()
if self.renderThread and self.renderThread.IsRunning() :
#todo
pass
else:
self.renderThread = RenderThread(doc)
print 'start thread successful: ', self.renderThread.Start()
return True
def RestoreLayout(self, sec_ref) :
pass
My goal is to render several pictures one after the other in the picture viewer. But the picture viewer doesn't open with this code (but if I launch the code directly in the plugin main thread it works). When I try to open the picture viewer from the menu after launching my plugin, I get an Access Violation and C4D terminates.
So how can i reach my goal? Thanks for any advice in advance!