Saving separately Z-buffer and color layers by one rendering pass

Hello guys,
could you help me with a problem that tortures me already for a month.
I would like to know how by script to save separately Z-buffer(aka depth, range) and color data when data is rendered.
In this case, what I am looking for is how by script to toggle consecutively RenderLayer -> [Combined, Depth] -> (Channels if Image to Draw) ??? and save color layer into a image file(e.g. PNG) and depth data into OPEN_EXR format, but without rendering the scene again(just using one rendering pass for both).

The only workaround(although non-script) so far was done by “Node Editor” where i have manually toggle the output of rendering [Z, Color] , but it requires two passes of rendering.

Could you help me to resolve the matter.
Thank you,
Mihail

P.S. (Since I am using open source library of EXR reader solution, I would not like to save both Z-buffer and color data together into a single file, because my “libre-source” software does not distinguish when more than 3 channels are saved(as it is a existing option for EXR files).

use the “file output node” in the node editor. Connect the combined pass into one “file output” node, connect the Z-pass into a second “file output” node

Yes, actually, this makes sense, but how to do this by script?

I would like to change name files dynamically for both file outputs.
I have to access nodes somehow and their properties.

BR,
Mihail

If you hover your mouse over the file output node, it gives a hint for the python code:


bpy.data.node_groups["Compositor Nodetree"].nodes["File Output"].base_path

However, when I type that in the python console, I find out that there is no node_group called “Compositor Nodetree”.
I don’t know what is going on here. A bug? a feature?

it is bit strange but you can access it via the scene, the node group you get returned is the one you want.


    >>> bpy.data.scenes['Scene'].node_tree
    bpy.data.node_groups['Compositing Nodetree']