# Viewport render info from Python

I'm writing a script to overcome some of Cycles' limitations in terms of performance, namely the loading time, which is very long in the case of heavy scenes.

I wrote a modal operator which, at the moment, creates a timer, toggles the current space fullscreen, and takes a screenshot at fixed intervals; since the viewport rendering does not reload the scene at each frame, part of the BVH building time, shaders update and device loading are done only once. I will of course use the real rendering for the final render, but this may prove useful for quickly rendering previews of a WIP.

What I'd like is to check for some values in the viewport, eg. samples rendered, rendering state (updating mesh, loading BVH, path tracing, etc.), in the same way as it is displayed at the top of the 3D View. This way I can check the current state and take the screenshot and set the next frame accordingly (eg. (pseudo-code) if samples_rendered > threshold: take_screenshot() and set_frame(current_frame+1). This wouldn't rely on an arbitrary timer, which doesn't account for the initial loading time, nor the time variations in rendering the frames.

Is there a way to access this information in Python?

• The viewport uses a different BVH structure which allows for individual objects to be dynamically updated without re-updating the whole scene, however it results in slower sampling speed. Not sure if using this method would actually end up being faster for final renders or not (where there are typically more samples), but it would be interesting to see some tests.. AFAIK You can't set the final render to use dynamic BVH without editing the source code, but you can set the viewport render to use static BVH (the kind the final render uses). Perhaps useful for testing. – gandalf3 Feb 10 '15 at 8:08
• Well, for light scenes I'm quite sure it wouldn't add any benefits, but the one I'm working on is really heavy, and since I don't need render passes, full sample count, motion blur, etc for preview purposes, it would definitely be faster in the viewport. – Pisurquatre Feb 10 '15 at 8:11
• The status as seen in the info area is set by native code, it can't be accessed with Python AFAIK. But you might want to look into app handlers, there's a callback right before and after a frame has been rendered - not sure if cycles supports it however. – CoDEmanX Feb 10 '15 at 10:21
• Cycles does support render handlers, but unfortunately they don't seem to work for viewport rendering, so I can't use them here. – Pisurquatre Feb 10 '15 at 12:21