fake-bpy-module icon indicating copy to clipboard operation
fake-bpy-module copied to clipboard

"type" argument of BlendDataNodeTrees.new() forces incorrect string "DUMMY"

Open arcusmaximus opened this issue 8 months ago • 3 comments
trafficstars

When calling bpy.data.node_groups.new(), you need to specify a node group name and a type name. The valid types can be found by calling it with an invalid type and looking at the error message:

CompositorNodeTree
TextureNodeTree
GeometryNodeTree
ShaderNodeTree

However, the type parameter is typed as Literal['DUMMY'] | None, making it impossible to specify any of these without using # type: ignore.

Ideally, the parameter would be constrained to (just) the valid class names, and the function would return the corresponding class so you can simply do the following:

bl_node_group = bpy.data.node_groups.new("My node group", "GeometryNodeTree")
# bl_node_group is automatically bpy.types.GeometryNodeTree
bl_node_group.is_modifier = True

arcusmaximus avatar Feb 24 '25 21:02 arcusmaximus