0
$\begingroup$

How can possible socket types be filtered in a custom node tree for group inputs and outputs? In node tree input/ output socket types is there a way to control which socket types appear? To test:

  1. Copy and paste the following code into Blender's text editor.
from bpy.types import NodeTree, NodeSocket, NodeSocketInterface
from bpy.utils import register_class, unregister_class
import nodeitems_utils
from nodeitems_utils import NodeCategory, NodeItem

class TestSocket(NodeSocket):
    bl_label = "Example socket"
    
    def draw_color(self,context,node):
        return (0,.5,8,1)
    
    def draw(self,context,layout,node,text):
        layout.label(text=text)

class TestSocketInt(NodeSocketInterface):
    bl_idname = "TestSocketInt"
    bl_socket_idname = "TestSocket"
    
    def draw_color(self,context):
        return (0,.5,.8,1)
    
    def draw(self,context,layout):
        layout.prop(self,"hide_value")

class TestTree(NodeTree):
    bl_label = "Test Tree"
    bl_icon = "NODETREE"
    

classes = (TestTree,TestSocket,TestSocketInt)
cats = [NodeCategory('EXAMPLE','Example',items = [NodeItem('NodeGroupInput')])]

def register():
    from bpy.utils import register_class
    for cls in classes:
        register_class(cls)
    nodeitems_utils.register_node_categories('EXAMPLE_NODES', cats)
    
def unregister():
    from bpy.utils import unregister_class
    for cls in classes:
        unregister_class(cls)
    nodeitems_utils.unregister_node_categories('EXAMPLE_NODES')

if __name__ == "__main__":
    register()
  1. Add a new "Test Tree".

  2. Add a group input node.

  3. Add "Example socket" input. Right here, how can this list be filtered? What I'm trying to mean

$\endgroup$
5
  • $\begingroup$ Do you mean how to control the items that appear in the Type dropdown? I don't think you can. $\endgroup$
    – Harry McKenzie
    Commented Sep 25, 2023 at 15:31
  • $\begingroup$ That's exactly what I meant. It is possible to filter this dropdown as seen in Sverchok node group sockets. $\endgroup$ Commented Sep 25, 2023 at 20:07
  • $\begingroup$ yeah but you won't get the answer on stack exchange. you would have to contact the developers on more in depth scripting. it's more complicated task to achieve. $\endgroup$
    – Harry McKenzie
    Commented Sep 26, 2023 at 1:30
  • 1
    $\begingroup$ Thank you @Harry McKenzie for your feedback. I may just ask Sverchok developers how they did it. $\endgroup$ Commented Sep 26, 2023 at 1:49
  • $\begingroup$ @BlenderEnthusiast did you happen to solve this? $\endgroup$ Commented Feb 19 at 11:16

1 Answer 1

0
$\begingroup$

You need to override valid_socket_type(idname) of class TestTree(NodeTree) https://docs.blender.org/api/master/bpy.types.NodeTree.html#bpy.types.NodeTree.valid_socket_type

$\endgroup$

You must log in to answer this question.

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