Geometry Nodes: link to output inside node group is invalid when created from Python #105619

Closed
opened 2023-03-09 22:32:57 +01:00 by Damien Picard · 8 comments
Member

System Information
Operating system: Linux-5.19.0-35-generic-x86_64-with-glibc2.36 64 Bits
Graphics card: NVIDIA GeForce RTX 3060 Laptop GPU/PCIe/SSE2 NVIDIA Corporation 4.5.0 NVIDIA 470.161.03

Blender Version
Broken: version: 3.5.0 Beta, branch: blender-v3.5-release, commit date: 2023-03-09 18:49, hash: 4912695e0004
Worked: 3.4.1, branch: blender-v3.4-release, commit date: 2022-12-19 17:00, hash: rB55485cb379f7

Short description of error
When using Python to create a new link between a node and a new socket in a Group Output node, the resulting link is invalid.

image

Exact steps for others to reproduce the error

  • Open the attached blend file.
  • Run the script. It creates a new link between the second Math node and the Group Output node.
  • The following message is printed in the terminal, meaning that the link is invalid: Valid: False.

This issue breaks the Lazy Connect feature from Node Wrangler.

Reported by @genesis2303 in blender/blender-addons#104470.

**System Information** Operating system: Linux-5.19.0-35-generic-x86_64-with-glibc2.36 64 Bits Graphics card: NVIDIA GeForce RTX 3060 Laptop GPU/PCIe/SSE2 NVIDIA Corporation 4.5.0 NVIDIA 470.161.03 **Blender Version** Broken: version: 3.5.0 Beta, branch: blender-v3.5-release, commit date: 2023-03-09 18:49, hash: `4912695e0004` Worked: 3.4.1, branch: blender-v3.4-release, commit date: 2022-12-19 17:00, hash: `rB55485cb379f7` **Short description of error** When using Python to create a new link between a node and a new socket in a Group Output node, the resulting link is invalid. ![image](/attachments/b364de4f-8544-46b4-a091-4d677cdb32e3) **Exact steps for others to reproduce the error** - Open the attached blend file. - Run the script. It creates a new link between the second Math node and the Group Output node. - The following message is printed in the terminal, meaning that the link is invalid: `Valid: False`. ----- This issue breaks the Lazy Connect feature from Node Wrangler. Reported by @genesis2303 in blender/blender-addons#104470.
Damien Picard added the
Priority
Normal
Type
Report
Status
Needs Triage
labels 2023-03-09 22:32:58 +01:00
Damien Picard added this to the Nodes & Physics project 2023-03-09 22:32:59 +01:00

Hello. API changes. The creation of a new socket should now be explicitly done by the user.
It's just as close to #105283 (although it doesn't seem to be a duplicate)

Hello. API changes. The creation of a new socket should now be explicitly done by the user. It's just as close to https://projects.blender.org/blender/blender/issues/105283 (although it doesn't seem to be a duplicate)
Iliya Katushenock added the
Interest
Nodes & Physics
Interest
Python API
labels 2023-03-09 22:35:43 +01:00
Author
Member

I see, thanks!

I see, thanks!
Blender Bot added
Status
Archived
and removed
Status
Needs Triage
labels 2023-03-09 22:47:40 +01:00

I believe this issue should be looked at again. I don't think it is a purposeful api change.

I believe this issue should be looked at again. I don't think it is a purposeful api change.
@benrugg https://wiki.blender.org/wiki/Reference/Release_Notes/3.5/Python_API#Node_Group_Input_Output_Creation_with_virtual_sockets

I don't know if I'm in the right section for this, but I hope to be of help to the Blender and Addon developer community 😊

From the wiki page: https://wiki.blender.org/wiki/Reference/Release_Notes/3.5/Python_API#Node_Group_Input_Output_Creation_with_virtual_sockets

Virtual sockets are the extra sockets added to group input and output nodes. Previously connecting a link to them would create an input or output in the corresponding node group. That feature was meant as a UI/UX feature though, and is now implemented differently in Blender and doesn't happen automatically. The correct way to add a group input from Python is to use node_tree.inputs.new(...) (7026096099).

I think this is a little mistake, It is not possible to recreate the same socket automatically as it happened before:

Using node_tree.inputs.new() or node_tree.interface.new_socket() We would not have access to the Min or Max Value of the node socket (Blender Standard) to which we want to connect the link!

For example i want to create the same socket of the "Metallic" from Principled BSDF, in order to connect from a new socket from "Group Input" node to the bsdf.inputs['Metallic'] as metallic_input

metallic_socket = ng.interface.new_socket("Metallic", in_out ='INPUT', socket_type = 'NodeSocketFloat')
metallic_socket.subtype = 'FACTOR'

# The real problem:
metallic_socket.min_value = 0.0
metallic_socket.max_value = 1.0
# Easy if know Every socket of the blender nodes 😅

Even knowing that the minimum value is 0.0 and the maximum value is 1.0, the nodes are constantly evolving and we would have no way of having compatibility with future versions, so in this case we do not have access to the minimum and maximum value of the Principled BSDF node of the Metallic socket

In my opinion
This is the real problem and I would like to underline it to bring it to your attention, there no longer seems to be a method to recreate a socket with the same properties without knowing the properties of all the sockets (And that's only visually, not at the API level!), whereas before this was set instantly as soon as it was connected to the socket 'CUSTOM' with links.new().

This means that you have to manually check the sockets of each Blender Node, and it doesn't really seem like a smart practice

makes managing addons really complicated. They used these APIs quite simply.

There seems to be no alternative way to get back to doing what was previously possible.

I apologize again if I'm not in the right section, and if possible please consider this issue seriously, as an addon developer this is a big obstacle.

I don't know if I'm in the right section for this, but I hope to be of help to the Blender and Addon developer community 😊 From the wiki page: [https://wiki.blender.org/wiki/Reference/Release_Notes/3.5/Python_API#Node_Group_Input_Output_Creation_with_virtual_sockets](url) > Virtual sockets are the extra sockets added to group input and output nodes. Previously connecting a link to them would create an input or output in the corresponding node group. That feature was meant as a UI/UX feature though, and is now implemented differently in Blender and doesn't happen automatically. The correct way to add a group input from Python is to use node_tree.inputs.new(...) (7026096099). I think this is a little mistake, It is not possible to recreate the same socket automatically as it happened before: Using node_tree.inputs.new() or node_tree.interface.new_socket() We would not have access to the Min or Max Value of the node socket (Blender Standard) to which we want to connect the link! For example i want to create the same socket of the "Metallic" from Principled BSDF, in order to connect from a new socket from "Group Input" node to the` bsdf.inputs['Metallic'] as metallic_input` ``` metallic_socket = ng.interface.new_socket("Metallic", in_out ='INPUT', socket_type = 'NodeSocketFloat') metallic_socket.subtype = 'FACTOR' # The real problem: metallic_socket.min_value = 0.0 metallic_socket.max_value = 1.0 # Easy if know Every socket of the blender nodes 😅 ``` **Even knowing that the minimum value is 0.0 and the maximum value is 1.0, the nodes are constantly evolving and we would have no way of having compatibility with future versions, so in this case we do not have access to the minimum and maximum value of the Principled BSDF node of the Metallic socket** In my opinion This is the real problem and I would like to underline it to bring it to your attention, there no longer seems to be a method to recreate a socket with the same properties without knowing the properties of all the sockets (And that's only visually, not at the API level!), whereas before this was set instantly as soon as it was connected to the socket 'CUSTOM' with links.new(). This means that you have to manually check the sockets of each Blender Node, and it doesn't really seem like a smart practice makes managing addons really complicated. They used these APIs quite simply. There seems to be no alternative way to get back to doing what was previously possible. I apologize again if I'm not in the right section, and if possible please consider this issue seriously, as an addon developer this is a big obstacle.
Author
Member

@Andrew_D Hi, I think this is a valid concern.
A new API was introduced in 3.6, bpy_extras.node_utils.connect_sockets(input, output) (!105975). It has the advantage that it handles the connections to or from virtual sockets.
However, it doesn’t currently copy the expected properties (min, max, default value, etc.). I’m trying to solve this but it looks like some information is not exposed to Python, such as the socket’s min and max values so I couldn’t find a way to do it in a reliable way yet.

@Andrew_D Hi, I think this is a valid concern. A new API was introduced in 3.6, `bpy_extras.node_utils.connect_sockets(input, output)` (!105975). It has the advantage that it handles the connections to or from virtual sockets. However, it doesn’t currently copy the expected properties (min, max, default value, etc.). I’m trying to solve this but it looks like some information is not exposed to Python, such as the socket’s min and max values so I couldn’t find a way to do it in a reliable way yet.

@Andrew_D Hi, I think this is a valid concern.
A new API was introduced in 3.6, bpy_extras.node_utils.connect_sockets(input, output) (!105975). It has the advantage that it handles the connections to or from virtual sockets.
However, it doesn’t currently copy the expected properties (min, max, default value, etc.). I’m trying to solve this but it looks like some information is not exposed to Python, such as the socket’s min and max values so I couldn’t find a way to do it in a reliable way yet.

I think the bpy_extras.node_utils.connect_sockets(input, output) not Working into Blender 4.0, try to connect Group Inputs.outputs Custom Socket to Gamma Inputs 'Gamma'

gi = nodes["Group Input"]
gamma = nodes["Gamma"]
node_utils.connect_sockets(gi.outputs[''], gamma.inputs['Gamma'])

Result:

Traceback (most recent call last):
  File "<blender_console>", line 1, in <module>
  File "\blender 4.0 beta\4.0\scripts\modules\bpy_extras\node_utils.py", line 44, in connect_sockets
    input_node.id_data.interface.new_socket(
TypeError: NodeTreeInterface.new_socket(): error with keyword argument "socket_type" -  enum "NodeSocketFloatUnsigned" not found in ('NodeSocketVector', 'NodeSocketShader', 'NodeSocketFloat', 'NodeSocketColor')

> @Andrew_D Hi, I think this is a valid concern. > A new API was introduced in 3.6, `bpy_extras.node_utils.connect_sockets(input, output)` (!105975). It has the advantage that it handles the connections to or from virtual sockets. > However, it doesn’t currently copy the expected properties (min, max, default value, etc.). I’m trying to solve this but it looks like some information is not exposed to Python, such as the socket’s min and max values so I couldn’t find a way to do it in a reliable way yet. I think the` bpy_extras.node_utils.connect_sockets(input, output)` not Working into Blender 4.0, try to connect Group Inputs.outputs **Custom Socket** to **Gamma** Inputs 'Gamma' ``` gi = nodes["Group Input"] gamma = nodes["Gamma"] node_utils.connect_sockets(gi.outputs[''], gamma.inputs['Gamma']) Result: Traceback (most recent call last): File "<blender_console>", line 1, in <module> File "\blender 4.0 beta\4.0\scripts\modules\bpy_extras\node_utils.py", line 44, in connect_sockets input_node.id_data.interface.new_socket( TypeError: NodeTreeInterface.new_socket(): error with keyword argument "socket_type" - enum "NodeSocketFloatUnsigned" not found in ('NodeSocketVector', 'NodeSocketShader', 'NodeSocketFloat', 'NodeSocketColor') ```
Author
Member

I think the bpy_extras.node_utils.connect_sockets(input, output) not Working into Blender 4.0

Indeed, I just opened !113630 to try and fix that! But I’m not sure my fix is good enough.

> I think the` bpy_extras.node_utils.connect_sockets(input, output)` not Working into Blender 4.0 Indeed, I just opened !113630 to try and fix that! But I’m not sure my fix is good enough.
Sign in to join this conversation.
No Label
Interest
Alembic
Interest
Animation & Rigging
Interest
Asset System
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
Asset Browser Project
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 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#105619
No description provided.