1
$\begingroup$

I am trying to enable backdrop in Blender using Python and using Blender's Python API (no GUI) but it seems that it is not as straight-forward as I thought. I know how to enable Use Nodes via bpy.context.scene.use_nodes = True and just need to enable backdrop. The most relevant Python documentation for backdrop Here is a bit unclear and I do not know exactly how I can enable backdropping through the NodeSpaceEditor class. Can someone explain how I can do that?

Update: it turns out that the Python documentation is useful when you are running Blender with the GUI. I need to enable backdrop when I am running Blender in the background.

The hard way is to compile Blender from scratch and enable backdropping by modifying the source code as explained here but this is too much of work. I hope there is a way to do it using Blender's Python API.

$\endgroup$
  • $\begingroup$ Do you see the python in the Info window as you change an editor to Node Editor and then change that to use a Compositor Node tree, and then tell it to 'use nodes' and 'show backdrop'? It is all of those and not just a single command that is involved here to use the backdrop, so we have to tell it to change or use each of those. $\endgroup$ – Craig D Jones Mar 14 '18 at 4:06
  • $\begingroup$ @CraigDJones Sorry I was assuming that we have done all of those steps except the backdrop part. Do you know how one can enable backdrop using Python in this case? I'm gonna update my question to make it clear. $\endgroup$ – Amir Mar 14 '18 at 4:13
  • $\begingroup$ Did you see the python in the info editor? bpy.context.space_data.show_backdrop = True This is what pops up, so it tells me that if I am in the Node Editor already and in the Compositor Node tree, then this allows me to tell it to use the back drop. $\endgroup$ – Craig D Jones Mar 14 '18 at 4:34
  • 4
    $\begingroup$ Loathe to answer your questions because there is always some caveat, like by python do you mean running bpy as a python module?. Quite simply the backdrop in your first link can be set via context.space_data.use_backdrop = True as long as the context.area.type == 'NODE_EDITOR' otherwise loop screen areas and if node editor type use area.spaces.active $\endgroup$ – batFINGER Mar 14 '18 at 10:55
  • 2
    $\begingroup$ Not sure I see the point of wanting a UI backdrop when running without a UI. $\endgroup$ – batFINGER Mar 14 '18 at 19:45
1
$\begingroup$

You can set this property, you just have to know which area is the node editor. Like this:

import bpy

def get_node_editor_area():
    """
    Get the index of the area containing the compositor
    """
    for i in range(len(bpy.context.screen.areas)):
        area = bpy.context.screen.areas[i]
        if area.type == 'NODE_EDITOR':
            return i

area_index = get_node_editor_area()
bpy.context.screen.areas[area_index].spaces[0].show_backdrop = True

If this is for an addon and the user will have the mouse in the node editor area when this function is called, I think you could use bpy.context.space_data.show_backdrop = True instead.

$\endgroup$
  • $\begingroup$ This seems to be only working when you are running Desktop (with UI) version of Blender. I couldn't run this when using Blender as module or when running Blender in the background. Did you also try doing that? When I print area.type in the for loop I get the followings: INFO, PROPERTIES ,TIMELINE, OUTLINER, VIEW_3D. When running with the GUI I also get NODE_EDITOR. $\endgroup$ – Amir Mar 14 '18 at 20:38
  • 1
    $\begingroup$ Why do you want to show the backdrop without running Blender's user interface? For my script to work, one of the areas open in blender must be the node editor. $\endgroup$ – doakey3 Mar 14 '18 at 20:46
  • $\begingroup$ Well I do not really need Backdrop to see something (because I cannot). I need to enable backdrop so that I can update the contents of the Viewer Node image block. Maybe you can take a look at my problem here; this might give you an idea of what I'm trying to do. This is also a bit relevant. Any help would be really appreciated. $\endgroup$ – Amir Mar 14 '18 at 20:48
  • $\begingroup$ I don't know much about running python in Blender without a UI, but have you tried setting one of the areas of Blender's UI to the Node Editor, then saving the startup file, then trying my script? Or perhaps loading a .blend file with one of the areas set to the Node editor when you run blender from the terminal. $\endgroup$ – doakey3 Mar 14 '18 at 21:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.