user: Show practical ways to work with SpaceNodeEditor(Space) in a Blender add-on or script – include code.

assistant: # SpaceNodeEditor(Space)

base classes — [`bpy_struct`](bpy.types.bpy_struct.html#bpy.types.bpy_struct "bpy.types.bpy_struct"), [`Space`](bpy.types.Space.html#bpy.types.Space "bpy.types.Space")

*class* bpy.types.SpaceNodeEditor(*Space*)
:   Node editor space data

    backdrop_channels
    :   Channels of the image to draw

        - `COLOR_ALPHA`
          Color & Alpha – Display image with RGB colors and alpha transparency.
        - `COLOR`
          Color – Display image with RGB colors.
        - `ALPHA`
          Alpha – Display alpha transparency channel.
        - `RED`
          Red.
        - `GREEN`
          Green.
        - `BLUE`
          Blue.

        Type:
        :   enum in [`'COLOR_ALPHA'`, `'COLOR'`, `'ALPHA'`, `'RED'`, `'GREEN'`, `'BLUE'`], default `'COLOR'`

    backdrop_offset
    :   Backdrop offset

        Type:
        :   float array of 2 items in [-inf, inf], default (0.0, 0.0)

    backdrop_zoom
    :   Backdrop zoom factor

        Type:
        :   float in [0.01, inf], default 1.0

    cursor_location
    :   Location for adding new nodes

        Type:
        :   [`mathutils.Vector`](mathutils.html#mathutils.Vector "mathutils.Vector") of 2 items in [-inf, inf], default (0.0, 0.0)

    edit_tree
    :   Node tree being displayed and edited

        Type:
        :   [`NodeTree`](bpy.types.NodeTree.html#bpy.types.NodeTree "bpy.types.NodeTree"), (readonly)

    id
    :   Data-block whose nodes are being edited

        Type:
        :   [`ID`](bpy.types.ID.html#bpy.types.ID "bpy.types.ID"), (readonly)

    id_from
    :   Data-block from which the edited data-block is linked

        Type:
        :   [`ID`](bpy.types.ID.html#bpy.types.ID "bpy.types.ID"), (readonly)

    insert_offset_direction
    :   Direction to offset nodes on insertion

        Type:
        :   enum in [`'RIGHT'`, `'LEFT'`], default `'RIGHT'`

    node_tree
    :   Base node tree from context

        Type:
        :   [`NodeTree`](bpy.types.NodeTree.html#bpy.types.NodeTree "bpy.types.NodeTree")

    node_tree_sub_type
    :   Type:
        :   enum in []

    overlay
    :   Settings for display of overlays in the Node Editor

        Type:
        :   [`SpaceNodeOverlay`](bpy.types.SpaceNodeOverlay.html#bpy.types.SpaceNodeOverlay "bpy.types.SpaceNodeOverlay"), (readonly, never None)

    path
    :   Path from the data-block to the currently edited node tree

        Type:
        :   [`SpaceNodeEditorPath`](bpy.types.SpaceNodeEditorPath.html#bpy.types.SpaceNodeEditorPath "bpy.types.SpaceNodeEditorPath") [`bpy_prop_collection`](bpy.types.bpy_prop_collection.html#bpy.types.bpy_prop_collection "bpy.types.bpy_prop_collection") of [`NodeTreePath`](bpy.types.NodeTreePath.html#bpy.types.NodeTreePath "bpy.types.NodeTreePath"), (readonly)

    pin
    :   Use the pinned node tree

        Type:
        :   boolean, default False

    selected_node_group
    :   Node group to edit

        Type:
        :   [`NodeTree`](bpy.types.NodeTree.html#bpy.types.NodeTree "bpy.types.NodeTree")

    shader_type
    :   Type of data to take shader from

        - `OBJECT`
          Object – Edit shader nodes from Object.
        - `WORLD`
          World – Edit shader nodes from World.
        - `LINESTYLE`
          Line Style – Edit shader nodes from Line Style.

        Type:
        :   enum in [`'OBJECT'`, `'WORLD'`, `'LINESTYLE'`], default `'OBJECT'`

    show_annotation
    :   Show annotations for this view

        Type:
        :   boolean, default False

    show_backdrop
    :   Use active Viewer Node output as backdrop for compositing nodes

        Type:
        :   boolean, default False

    show_gizmo
    :   Show gizmos of all types

        Type:
        :   boolean, default False

    show_gizmo_active_node
    :   Context sensitive gizmo for the active node

        Type:
        :   boolean, default True

    show_region_asset_shelf
    :   Display a region with assets that may currently be relevant (such as brushes in paint modes, or poses in Pose Mode)

        Type:
        :   boolean, default False

    show_region_toolbar
    :   Type:
        :   boolean, default False

    show_region_ui
    :   Type:
        :   boolean, default False

    supports_previews
    :   Whether the node editor’s type supports displaying node previews

        Type:
        :   boolean, default False, (readonly)

    texture_type
    :   Type of data to take texture from

        - `WORLD`
          World – Edit texture nodes from World.
        - `BRUSH`
          Brush – Edit texture nodes from Brush.
        - `LINESTYLE`
          Line Style – Edit texture nodes from Line Style.

        Type:
        :   enum in [`'WORLD'`, `'BRUSH'`, `'LINESTYLE'`], default `'WORLD'`

    tree_type
    :   Node tree type to display and edit

        - `GeometryNodeTree`
          Geometry Node Editor – Advanced geometry editing and tools creation using nodes.
        - `CompositorNodeTree`
          Compositor – Create effects and post-process renders, images, and the 3D Viewport.
        - `ShaderNodeTree`
          Shader Editor – Edit materials, lights, and world shading using nodes.
        - `TextureNodeTree`
          Texture Node Editor – Edit textures using nodes.

        Type:
        :   enum in [`'GeometryNodeTree'`, `'CompositorNodeTree'`, `'ShaderNodeTree'`, `'TextureNodeTree'`], default `'DEFAULT'`

    cursor_location_from_region(*x*, *y*)
    :   Set the cursor location using region coordinates

        Parameters:
        :   - **x** (*int in* *[**-inf**,* *inf**]*) – x, Region x coordinate
            - **y** (*int in* *[**-inf**,* *inf**]*) – y, Region y coordinate

    *classmethod* bl_rna_get_subclass(*id*, *default=None*, */*)
    :   Parameters:
        :   **id** (*str*) – The RNA type identifier.

        Returns:
        :   The RNA type or default when not found.

        Return type:
        :   [`bpy.types.Struct`](bpy.types.Struct.html#bpy.types.Struct "bpy.types.Struct") subclass

    *classmethod* bl_rna_get_subclass_py(*id*, *default=None*, */*)
    :   Parameters:
        :   **id** (*str*) – The RNA type identifier.

        Returns:
        :   The class or default when not found.

        Return type:
        :   type

    *classmethod* draw_handler_add(*callback*, *args*, *region_type*, *draw_type*)
    :   Add a new draw handler to this space type.
        It will be called every time the specified region in the space type will be drawn.
        Note: All arguments are positional only for now.

        Parameters:
        :   - **callback** (*Callable**[**...**,* *Any**]*) – A function that will be called when the region is drawn.
              It gets the specified arguments as input, it’s return value is ignored.
            - **args** (*tuple**[**Any**,* *...**]*) – Arguments that will be passed to the callback.
            - **region_type** (*str*) – The region type the callback draws in; usually `WINDOW`. ([`bpy.types.Region.type`](bpy.types.Region.html#bpy.types.Region.type "bpy.types.Region.type"))
            - **draw_type** (*str*) – Usually `POST_PIXEL` for 2D drawing and `POST_VIEW` for 3D drawing. In some cases `PRE_VIEW` can be used. `BACKDROP` can be used for backdrops in the node editor.

        Returns:
        :   Handler that can be removed later on.

        Return type:
        :   object

    *classmethod* draw_handler_remove(*handler*, *region_type*)
    :   Remove a draw handler that was added previously.

        Parameters:
        :   - **handler** (*object*) – The draw handler that should be removed.
            - **region_type** (*str*) – Region type the callback was added to.