Runtime error on trying to create new input/output to node groups via python #103150

Closed
opened 2022-12-12 07:14:05 +01:00 by Netherby · 7 comments

System Information
Operating system: Windows-10-10.0.19045-SP0 64 Bits
Graphics card: NVIDIA GeForce GTX 1070/PCIe/SSE2 NVIDIA Corporation 4.5.0 NVIDIA 516.94

Blender Version
Broken: version: 3.4.0, branch: blender-v3.4-release, commit date: 2022-12-06 18:46, hash: a95bf1ac01
Worked: 3.3

Short description of error
Previously it was possible to create new inputs and outputs on node groups (such as 'ShaderNodeGroup') using the python interface by calling 'new('socket type', 'name')' on a node groups inputs and outputs list. This now causes runtime error due I believe to this commit: https://developer.blender.org/rB52bd198153ede3c7131df895bb08e4828aab1e9b

Exact steps for others to reproduce the error
Simply execute this python script to create a material, add a shader node group and attempt to create a new input to it:

import bpy
mat = bpy.data.materials.new("Test")
mat.use_nodes = True
grptree = bpy.data.node_groups.new("testgrp", 'ShaderNodeTree')
grp = mat.node_tree.nodes.new('ShaderNodeGroup')
grp.node_tree = grptree
grp.inputs.new('NodeSocketColor', 'New Input') # Crash in 3.4: 'RuntimeError: Error: Cannot add socket to built-in node'
**System Information** Operating system: Windows-10-10.0.19045-SP0 64 Bits Graphics card: NVIDIA GeForce GTX 1070/PCIe/SSE2 NVIDIA Corporation 4.5.0 NVIDIA 516.94 **Blender Version** Broken: version: 3.4.0, branch: blender-v3.4-release, commit date: 2022-12-06 18:46, hash: `a95bf1ac01` Worked: 3.3 **Short description of error** Previously it was possible to create new inputs and outputs on node groups (such as 'ShaderNodeGroup') using the python interface by calling 'new('socket type', 'name')' on a node groups inputs and outputs list. This now causes runtime error due I believe to this commit: https://developer.blender.org/rB52bd198153ede3c7131df895bb08e4828aab1e9b **Exact steps for others to reproduce the error** Simply execute this python script to create a material, add a shader node group and attempt to create a new input to it: ``` import bpy mat = bpy.data.materials.new("Test") mat.use_nodes = True grptree = bpy.data.node_groups.new("testgrp", 'ShaderNodeTree') grp = mat.node_tree.nodes.new('ShaderNodeGroup') grp.node_tree = grptree grp.inputs.new('NodeSocketColor', 'New Input') # Crash in 3.4: 'RuntimeError: Error: Cannot add socket to built-in node' ```
Author

Added subscriber: @JerahmyPocott

Added subscriber: @JerahmyPocott
Member

Added subscriber: @HooglyBoogly

Added subscriber: @HooglyBoogly
Member

Changed status from 'Needs Triage' to: 'Archived'

Changed status from 'Needs Triage' to: 'Archived'
Member

In this case, the correct thing to do is use grptree.inputs.new instead of grp.inputs.new.
This is the difference that I mentioned in the comments of the commit. Inputs must be added to the node group itself, not the group node that uses the node group.
Since this is an expected change to the API with a very simple workaround, I will close this task.

In this case, the correct thing to do is use `grptree.inputs.new` instead of `grp.inputs.new`. This is the difference that I mentioned in the comments of the commit. Inputs must be added to the node group itself, not the group node that uses the node group. Since this is an expected change to the API with a very simple workaround, I will close this task.

Now fails with:

grptree.inputs.new('NodeSocketColor', 'New Input')
AttributeError: 'ShaderNodeTree' object has no attribute 'inputs'

If i use links it kind of works:

grptree.links.new('NodeSocketColor', 'New Input')

But it seems i need to pass an enum for the NodeSocketType.

Here are the NodeSocketTypes https://docs.blender.org/api/current/bpy_types_enum_items/node_socket_type_items.html
But no description how to use them. If i use them as a string obviously that doesn't work:

grptree.links.new('GEOMETRY', 'New Input')

Also tried to guess the implementation with:

grptree.links.new(bpy.types.SharedEnumItems.NodeSocketTypeItems.GEOMETRY, 'New Input')
AttributeError: 'module' object has no attribute 'SharedEnumItems'

With:

print(help(bpy.types))

I found the bpy_types.NodeSocket(builtins.bpy_struct) / NodeSocketStandard / NodeSocketGeometry enum.
But that seems not to work:

grptree.links.new(bpy.types.NodeSocket.NodeSocketStandard.NodeSocketGeometry, 'New Input')
AttributeError: type object 'NodeSocket' has no attribute 'NodeSocketStandard'

Also ignoring the hierarchy does not work:

grptree.links.new(bpy.types.NodeSocket.NodeSocketGeometry, 'New Input')
AttributeError: type object 'NodeSocket' has no attribute 'NodeSocketGeometry'

Also trying to use the GEOMETRY enum is not working:

grptree.links.new(bpy.types.NodeSocket.GEOMETRY, 'New Input')
AttributeError: type object 'NodeSocket' has no attribute 'GEOMETRY'

Also expecting the GEMOETRY enum is somehow magically available in the bpy.types does not work:

grptree.links.new(bpy.types.GEOMETRY, 'New Input')
AttributeError: 'module' object has no attribute 'GEOMETRY'

When i use the NodeSocketGeometry directly it fails as well:

grptree.links.new(bpy.types.NodeSocketGeometry, 'New Input')
TypeError: NodeLinks.new(): error with argument 1, "input" -  Function.input expected a NodeSocket type, not RNAMetaPropGroup
Now fails with: ```python grptree.inputs.new('NodeSocketColor', 'New Input') AttributeError: 'ShaderNodeTree' object has no attribute 'inputs' ``` If i use `links` it kind of works: ```python grptree.links.new('NodeSocketColor', 'New Input') ``` But it seems i need to pass an enum for the NodeSocketType. Here are the NodeSocketTypes https://docs.blender.org/api/current/bpy_types_enum_items/node_socket_type_items.html But no description how to use them. If i use them as a string obviously that doesn't work: ```python grptree.links.new('GEOMETRY', 'New Input') ``` Also tried to guess the implementation with: ```python grptree.links.new(bpy.types.SharedEnumItems.NodeSocketTypeItems.GEOMETRY, 'New Input') ``` ```shell AttributeError: 'module' object has no attribute 'SharedEnumItems' ``` With: ```python print(help(bpy.types)) ``` I found the `bpy_types.NodeSocket(builtins.bpy_struct) / NodeSocketStandard / NodeSocketGeometry` enum. But that seems not to work: ```python grptree.links.new(bpy.types.NodeSocket.NodeSocketStandard.NodeSocketGeometry, 'New Input') ``` ```shell AttributeError: type object 'NodeSocket' has no attribute 'NodeSocketStandard' ``` Also ignoring the hierarchy does not work: ```python grptree.links.new(bpy.types.NodeSocket.NodeSocketGeometry, 'New Input') ``` ```shell AttributeError: type object 'NodeSocket' has no attribute 'NodeSocketGeometry' ``` Also trying to use the `GEOMETRY` enum is not working: ```python grptree.links.new(bpy.types.NodeSocket.GEOMETRY, 'New Input') ``` ```shell AttributeError: type object 'NodeSocket' has no attribute 'GEOMETRY' ``` Also expecting the `GEMOETRY` enum is somehow magically available in the `bpy.types` does not work: ```python grptree.links.new(bpy.types.GEOMETRY, 'New Input') ``` ```shell AttributeError: 'module' object has no attribute 'GEOMETRY' ``` When i use the `NodeSocketGeometry` directly it fails as well: ```python grptree.links.new(bpy.types.NodeSocketGeometry, 'New Input') ``` ```shell TypeError: NodeLinks.new(): error with argument 1, "input" - Function.input expected a NodeSocket type, not RNAMetaPropGroup ```
Seems old API. https://wiki.blender.org/wiki/Reference/Release_Notes/4.0/Python_API#Breaking_changes

In this case, the correct thing to do is use grptree.inputs.new instead of grp.inputs.new.
This is the difference that I mentioned in the comments of the commit. Inputs must be added to the node group itself, not the group node that uses the node group.
Since this is an expected change to the API with a very simple workaround, I will close this task.

This is still broken in 4.0.2.

AttributeError: 'GeometryNodeTree' object has no attribute 'inputs'

It worked in 3.6, but inputs have been removed from GeometryNodeTree. There is currently no work around.

Edit:
Adding node groups inputs works only for custom node groups and it works like this:

C.window.screen.areas[4].spaces[0].node_tree.nodes['Group'].inputs.new('MySocketType', 'name')

> In this case, the correct thing to do is use `grptree.inputs.new` instead of `grp.inputs.new`. > This is the difference that I mentioned in the comments of the commit. Inputs must be added to the node group itself, not the group node that uses the node group. > Since this is an expected change to the API with a very simple workaround, I will close this task. This is still broken in 4.0.2. `AttributeError: 'GeometryNodeTree' object has no attribute 'inputs'` It worked in 3.6, but inputs have been removed from GeometryNodeTree. There is currently no work around. Edit: Adding node groups inputs works only for custom node groups and it works like this: `C.window.screen.areas[4].spaces[0].node_tree.nodes['Group'].inputs.new('MySocketType', 'name')`
Sign in to join this conversation.
No Label
Interest
Alembic
Interest
Animation & Rigging
Interest
Asset Browser
Interest
Asset Browser Project Overview
Interest
Audio
Interest
Automated Testing
Interest
Blender Asset Bundle
Interest
BlendFile
Interest
Collada
Interest
Compatibility
Interest
Compositing
Interest
Core
Interest
Cycles
Interest
Dependency Graph
Interest
Development Management
Interest
EEVEE
Interest
EEVEE & Viewport
Interest
Freestyle
Interest
Geometry Nodes
Interest
Grease Pencil
Interest
ID Management
Interest
Images & Movies
Interest
Import Export
Interest
Line Art
Interest
Masking
Interest
Metal
Interest
Modeling
Interest
Modifiers
Interest
Motion Tracking
Interest
Nodes & Physics
Interest
OpenGL
Interest
Overlay
Interest
Overrides
Interest
Performance
Interest
Physics
Interest
Pipeline, Assets & IO
Interest
Platforms, Builds & Tests
Interest
Python API
Interest
Render & Cycles
Interest
Render Pipeline
Interest
Sculpt, Paint & Texture
Interest
Text Editor
Interest
Translations
Interest
Triaging
Interest
Undo
Interest
USD
Interest
User Interface
Interest
UV Editing
Interest
VFX & Video
Interest
Video Sequencer
Interest
Virtual Reality
Interest
Vulkan
Interest
Wayland
Interest
Workbench
Interest: X11
Legacy
Blender 2.8 Project
Legacy
Milestone 1: Basic, Local Asset Browser
Legacy
OpenGL Error
Meta
Good First Issue
Meta
Papercut
Meta
Retrospective
Meta
Security
Module
Animation & Rigging
Module
Core
Module
Development Management
Module
EEVEE & Viewport
Module
Grease Pencil
Module
Modeling
Module
Nodes & Physics
Module
Pipeline, Assets & IO
Module
Platforms, Builds & Tests
Module
Python API
Module
Render & Cycles
Module
Sculpt, Paint & Texture
Module
Triaging
Module
User Interface
Module
VFX & Video
Platform
FreeBSD
Platform
Linux
Platform
macOS
Platform
Windows
Priority
High
Priority
Low
Priority
Normal
Priority
Unbreak Now!
Status
Archived
Status
Confirmed
Status
Duplicate
Status
Needs Info from Developers
Status
Needs Information from User
Status
Needs Triage
Status
Resolved
Type
Bug
Type
Design
Type
Known Issue
Type
Patch
Type
Report
Type
To Do
No Milestone
No project
No Assignees
4 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: blender/blender#103150
No description provided.