0
$\begingroup$

I'm writing an addon which allows for custom node sockets to be added to the inputs and outputs of node groups.

bl_space_type = 'NODE_EDITOR'
bl_region_type = 'UI'

With these tags, the panel appears in the shader node editor as wanted, but I would prefer to have the panel only display while editing a custom group, like the built-in panel for editing custom groups' sockets. How would I go about doing that?

$\endgroup$

1 Answer 1

1
$\begingroup$

Use poll() to check whether the panel can be drawn.

API: https://docs.blender.org/api/current/bpy.types.Panel.html#bpy.types.Panel.poll

import bpy
from bpy.types import Panel


class NODE_PT_custom_panel(Panel):
    bl_space_type = 'NODE_EDITOR'
    bl_region_type = 'UI'
    bl_category = "Custom"
    bl_label = "Layout"
    
    @classmethod
    def poll(cls, context):
        snode = context.space_data
        if snode is None:
            return False
        tree = snode.edit_tree
        if tree is None:
            return False
        if tree.is_embedded_data:
            return False
        return True

    def draw(self, context):
        layout = self.layout

        layout.label(text='Hello World')


def register():
    bpy.utils.register_class(NODE_PT_custom_panel)


def unregister():
    bpy.utils.unregister_class(NODE_PT_custom_panel)


if __name__ == "__main__":
    register()
$\endgroup$
2
  • $\begingroup$ Thank you! Specifically, the "is_embedded_data" tag helped a lot but I also didn't know about the "edit_tree". $\endgroup$
    – gcs_dev
    Commented Jun 30, 2023 at 16:32
  • 1
    $\begingroup$ the edit_tree is the current node_tree $\endgroup$
    – Karan
    Commented Jun 30, 2023 at 16:49

You must log in to answer this question.

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