Node auto frame

I’m looking into creating a script that automatically frames all nodes when you switch to either the Shader or Compositor workspaces

I understand that within a script, the command bpy.ops.node.view_all() should be called using context (which I haven’t figured out yet).

At the moment, I’ve been able to get the script to monitor what workspace the user is in:

import bpy

def rna_callback():
    print (bpy.context.workspace)

def subscribe():
    handle = object()
        key=(bpy.types.Window, "workspace"),
        args=(),  # Callback args
    return handle

def unsubscribe(handle):

if __name__ == "__main__":
    bpy._handle = subscribe()

I’m trying to understand how I can call bpy.ops.node.view_all() within this script (the next step would be putting it in a IF statement to only call it when the user enters the Shader or Compositor workspace).

I know that the function is only a keypress away so my idea seems a bit lazy, but I’m trying to change some repetitive tasks to something Blender could do automatically.

Of course, if there’s an addon that automatically does this task, I would WAY more choose that than scripting this.

Thanks for any help you could provide! :slight_smile: :slightly_smiling_face:

1 Like

the trick for this one is figuring out how to call bpy.ops.node.view_all() from the wrong context. typically you would just override the context once you know what the operator is polling for, but after looking at the source for NODE_OT_view_all in the source code and seeing that it’s only polling for a valid NODE_EDITOR area and space data (ie: a material selected), I’m unable to make the operator actually perform the framing action, it just returns {‘FINISHED’} without doing anything which means it’s failing somewhere in the operator’s exec function.

ignore my two errors due to typos:

Right, it’s a matter of making the call from within the context of the node editor window itself.