2
$\begingroup$

I am using blender as a python module and want to use this trick to get rendering results without saving on the disk: https://ammous88.wordpress.com/2015/01/16/blender-access-render-results-pixels-directly-from-python-2/

The exact code described in the link works when I execute it in the python console of the blender program. However, it does not work, if I simply run it with python or by calling blender -b -P script.py. In those cases, bpy.data.images['Viewer Node'].pixels contains 256*256 zeros instead of the rendered cube.

I would appreciate very much any tips concerning what the origin of this difference in behavior is, and how to eliminate it. My guess would be, that some configuration of blender is different when starting the program compared to importing bpy in python, but I have no clue where to search for.

$\endgroup$
6
  • $\begingroup$ first you can't just run it in python (outside blender ) , second when running a render script you have to omit the -b because blender can't render while in the background (without a gui ) $\endgroup$
    – Chebhou
    Commented Mar 28, 2015 at 1:19
  • $\begingroup$ have you tried that ? $\endgroup$
    – Chebhou
    Commented Mar 28, 2015 at 1:37
  • $\begingroup$ Thank you for the tip with -b. However, I thought, it should be possible to run the script outside blender with python. I followed the instructions of building blender to use it as a python module: wiki.blender.org/index.php/User:Ideasman42/BlenderAsPyModule . Also, rendering and saving the image to a file works when running outside blender with python. Just the trick to directly access the pixels didn't work. (Which would be important for me.) $\endgroup$
    – Philipp
    Commented Mar 28, 2015 at 1:37
  • $\begingroup$ ok since you have built blender that way it is possible , but i haven't tried that before $\endgroup$
    – Chebhou
    Commented Mar 28, 2015 at 1:45
  • $\begingroup$ i tried your code, and it looks like something strange is happening with the activation of the node tree when you run the script from the command line. I tried running the code, with an added save file at the end. when i open that file up in blender the node tree isnt correctly linked to the scene, i have to change to materials and back for it to show. I think this could be a a bug report. $\endgroup$
    – wardrums
    Commented Mar 29, 2015 at 3:58

1 Answer 1

2
$\begingroup$

running blender -b -P script.py will start blender in background mode, notice the -b option. For that reason all Viewer nodes will be deactivated and set to default size 256*256.

Try removing the -b option.

$\endgroup$
4
  • $\begingroup$ Thank you. Do you know, whether it is possible to activate the Viewer nodes when using blender as a python module? It would be important for me to run it on a server and get the rendering result as fast as possible, without saving to a disk. $\endgroup$
    – Philipp
    Commented Mar 30, 2015 at 22:37
  • $\begingroup$ never tried that. but my guess is: No. Simply because Viewer Nodes are Gui related components, and running blender as python module most probably is using background mode. If you really need to get results as fast as possible why don't you run blender in a python subprocess without background mode. $\endgroup$
    – wsfax
    Commented Mar 31, 2015 at 7:57
  • $\begingroup$ Is it possible to run blender without background mode on a server? When trying this, I get: 'Unable to open a display Aborted (core dumped)' $\endgroup$
    – Philipp
    Commented Apr 1, 2015 at 23:04
  • $\begingroup$ Would this discussion be considered as off-topic concerning the initial question? Then I would mark your contribution as the answer and open a new question. $\endgroup$
    – Philipp
    Commented Apr 1, 2015 at 23:06

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .