I am using two Viewer nodes to directly access pixel values of the rendering through bpy.data.images['Viewer Node'].pixels
.I want to access the outputs of both of these nodes by activating them one by one using Python. However, it seems that I cannot activate them via Python. If I click on either of them the Viewer Node data block is immediately updated as the sum of the pixel values shows. For instance, clicking on Viewer2:
And doing np.array(bpy.data.images['Viewer Node'].pixels[:]).sum()
will give me 292007.42460217333
Clicking on Viewer1 and doing np.array(bpy.data.images['Viewer Node'].pixels[:]).sum()
will result in a different number. Doing the followings will not activate either of the Viewer nodes and I will always get the same number in the np.sum():
v1 = bpy.context.scene.node_tree.nodes['Viewer']
v2 = bpy.context.scene.node_tree.nodes['Viewer.001']
v1.select = True
v2.select = False
np.array(bpy.data.images['Viewer Node'].pixels[:]).sum()
292007.42460217333`
v1.select = False
v2.select = True
np.array(bpy.data.images['Viewer Node'].pixels[:]).sum()
292007.42460217333`
I also tried bpy.context.scene.node_tree.nodes.active = v1
after v1.select = True
and v2.select = False
lines but it still does not work.
None of these activate either of the Viewer nodes. It seems that I am doing the same thing as shown in the solutions provided here but I cannot activate the nodes, or update the image block without re-rendering. Another solution that I found is this one. However, it seems that Blender's Python API has changed a little bit for the newer versions of Blender (I am using 2.79) and I cannot use the method provided.
A promising solution seems to be coming from invoking clicking events as shown here but I don't know how I can do it for selecting nodes. So I wonder, does any one know how to activate the Viewer nodes via Python, possibly via invoking LBM events?