5
$\begingroup$

Here's another little issue I can't solve by myself:

I wrote a little python script called by blender from terminal (or dos cmd) that renders a scene letting you see the tiles composing the image like it does from "inside Blender" hitting the f12 button.

Now, I would like to popup a window with no menus and with the render result fitted in it.

This is what I do from terminal:

blender /path/to/file.blend -p 200 200 640 480 -P /path/to/python/script

This is the content of the python script:

import bpy
bpy.data.screens['screen_name'].scene = bpy.data.scenes['scene_name']
bpy.context.window.screen = bpy.data.screens['screen_name']
bpy.context.screen.scene = bpy.data.scenes['scene_name']

bpy.data.scenes['scene_name'].cycles.samples = 40
bpy.data.scenes['scene_name'].render.resolution_percentage = 50

#this "for" breaks all the code
for area in bpy.context.screen.areas:
   if area.type == 'IMAGE_EDITOR':
       override = bpy.context.copy()
       override['area'] = area
       bpy.ops.screen.screen_full_area(override, use_hide_panels=True)
       bpy.ops.image.view_all(override, fit_view=False)
       break

#what under work as intended without the "for"
bpy.ops.render.view_show('INVOKE_DEFAULT')
#renderizza
bpy.ops.render.render('INVOKE_DEFAULT', animation=False, write_still=True, use_viewport=False, scene='scene_name')

As I wrote in the comment in the py code, everything works just fine without the "for" code. The error I got on Ubuntu is

RuntimeError: Operator bpy.ops.image.view_all.poll() failed, context is incorrect

On windows it adds a EXCEPTION_ACCESS_VIOLATION (windows always have to make some sort of drama :-)

What did I do wrong?

Thank you for your time and for you help.

$\endgroup$

1 Answer 1

4
$\begingroup$

Screen Full Area Opens a new Screen

A couple of prints in the following show that the context screen and henceforth area, after calling the bpy.ops.screen.screen_full_area() operator are not the same. Change the override dictionary accordingly. (btw running view all without the override core dumps my blender (ubuntu 18))

import bpy

context = bpy.context
for area in bpy.context.screen.areas:
   if area.type == 'IMAGE_EDITOR':
       override = bpy.context.copy()
       override['space_data'] = area.spaces.active
       override['region'] = area.regions[-1]
       override['area'] = area
       bpy.ops.screen.screen_full_area(override, use_hide_panels=True)

       print(context.area, override['area'])
       print(context.screen, override['screen'])
       print(context.window, override['window'])
       override['screen'] = context.screen
       override["area"] = context.area
       bpy.ops.image.view_all(override, fit_view=True)
       break
$\endgroup$
1
  • $\begingroup$ Thank you man! This works, but it raises more questions that answers to me (but this is another story :-). I just had for some reason to get rid of blank lines and of course add the render command itself at the end of the file, outside of the for loop, plus many other command at the beginning (like importing objects and other stuff my script is supposed to do. Thanks again you PRO. $\endgroup$ May 1, 2018 at 15:47

You must log in to answer this question.

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