# pre render script behaviour

I use simple python snippets to replicate the light pass manager (LPM) script's behaviour for 3dsmax link.

LPM in 3dsmax basically just runs a pre_render script that applies overrides and then renders.

Blender can do the same thing with bpy.app.handlers.render_pre

It works alright, but there is one essential thing that doesnt work as I expected it:

-in 3dsmax, the pre_render_script is only run on the data that is sent to the renderer. The scene in front of the user is unchanged.

-in Blender, the pre_render_script is run on the scene before it is sent to the renderer. Therefore, after rendering, the scene in the viewport has all changes applied and the original state of the scene is lost.

I dont want to write scripts that record the whole state of the scene so it can be rebuilt post render. It is error-prone, needs to be maintained, I am a python noob and besides that, Blender has all the data already stored in the file.

My workaround right now
start the render as a subprocess and run the python script that sets the overrides:

render_cmd = '''\
gnome-terminal --
/usr/bin/blender -b
%s
--python %s
-S Scene -s 1 -e 1 -a
''' % (fname, render_prep_script_name)
subprocess.call(render_cmd.split())


This is not bad, I can work with that. But I have to wait for the renderer to save the output image before I can see it. So I am wondering, should the behaviour of the render_pre handler not be different?

• yes, this is a simple and good solution and should work fine. But what about heavy production scenes? I feel like I dont want to copy all that data everytime I hit render. – cookiemonsterandthegirls Apr 24 '19 at 8:29
• I'm already attempting to answer in the comments, I'll post my suggestions as a proper answer, so that it can be voted by the community. – Leander Apr 24 '19 at 8:32

• The above solution can be improved by making a linked copy (LINK_OBJECTS). It will not take up much more memory, since the data blocks the same. Then (on the copy) make the datablocks you want to change single users and change them.