# Render layer selection when rendering via python

I'm working on a script that renders certain render layers defined in the operator. The script is supposed to make a list of currently enabled render layers, disable all of them, and then enable the layers specified in the operator, render, and then revert the enabled layers to what they were at the start. But, when I run it, the render is always of the layers enabled at the start. However, if I remove the INVOKE_DEFAULT argument from the render command, it works properly. But then it doesn't show the render progress.

What is going on? Is there a better way to do this?

Here is the relevant code snippet:

startlayers = []
enabled_list = [*desired layers*]

for x in bpy.context.scene.render.layers:
startlayers.append(x.use)
x.use = False

for x in enabled_list:
bpy.context.scene.render.layers[x].use = True

bpy.ops.render.render('INVOKE_DEFAULT',scene="Cycles")

for x in range(len(startlayers)):
bpy.context.scene.render.layers[x].use = startlayers[x]

• If you can, use the compositor. By passing INVOKE_DEFAULT the operator is only called one time... One workaround is setting up a modal operator along with some crazy handlers: blender.stackexchange.com/a/71830/31447 However, that's error prone as hell if you don't know what you are doing. – brockmann Jul 25 '18 at 10:03
• I run into problems with the compositor too. If I use the command shown in the compositor render layer nodes, then I get no render progress unless I use INVOKE_DEFAULT, but then it can only render 1 layer at a time. Asking about that here: blender.stackexchange.com/questions/114697/… – Drudge Jul 25 '18 at 18:12
• IMO that's a waste of time, there is no good solution and not even a good approach atm... – brockmann Jul 26 '18 at 14:03