Node: Incorrect node socket indexing when connecting with python #103395

Closed
opened 2022-12-22 05:45:48 +01:00 by Paul Szajner · 26 comments

System Information
Operating system: Linux-5.10.0-13-amd64-x86_64-with-glibc2.31 64 Bits
Graphics card: GeForce GTX 1080/PCIe/SSE2 NVIDIA Corporation 4.5.0 NVIDIA 460.91.03

Blender Version
Broken: version: 3.5.0 Alpha, branch: master, commit date: 2022-12-21 20:25, hash: cef5841e12
Worked: (newest version of Blender that worked as expected)

Short description of error
Trying to connect a mix node (former MixRGB) to another node using tree.links.new() doesn't work.

Exact steps for others to reproduce the error
Open the attached .blend file bug_plug_nodes.blend
It contains a cube with a materials and some nodes inside :
image.png

You can then run the script, and test different combinations, the last one work but not the others.

**System Information** Operating system: Linux-5.10.0-13-amd64-x86_64-with-glibc2.31 64 Bits Graphics card: GeForce GTX 1080/PCIe/SSE2 NVIDIA Corporation 4.5.0 NVIDIA 460.91.03 **Blender Version** Broken: version: 3.5.0 Alpha, branch: master, commit date: 2022-12-21 20:25, hash: `cef5841e12` Worked: (newest version of Blender that worked as expected) **Short description of error** Trying to connect a mix node (former MixRGB) to another node using tree.links.new() doesn't work. **Exact steps for others to reproduce the error** Open the attached .blend file [bug_plug_nodes.blend](https://archive.blender.org/developer/F14082061/bug_plug_nodes.blend) It contains a cube with a materials and some nodes inside : ![image.png](https://archive.blender.org/developer/F14082064/image.png) You can then run the script, and test different combinations, the last one work but not the others.
Author

Added subscriber: @sozap

Added subscriber: @sozap

#104029 was marked as duplicate of this issue

#104029 was marked as duplicate of this issue

#103922 was marked as duplicate of this issue

#103922 was marked as duplicate of this issue

#103642 was marked as duplicate of this issue

#103642 was marked as duplicate of this issue

blender/blender-addons#103205 was marked as duplicate of this issue

blender/blender-addons#103205 was marked as duplicate of this issue

Added subscriber: @cassidy

Added subscriber: @cassidy

For some reason, first output seems to be the third in the outputs list.

tree.links.new(na.outputs[2], nb.inputs["Surface"])

And for the inputs, although the first socket is index 0 (correct), second and third input is index 6 and 7, respectively)

tree.links.new(na.outputs[2], nc.inputs[0])    # Factor
tree.links.new(na.outputs[2], nc.inputs[6])    # A
tree.links.new(na.outputs[2], nc.inputs[7])    # B

And I agree, this doesn't seem normal.

EDIT:
Above was observed in Blender version:
3.4.0, branch: blender-v3.4-release, commit date: 2022-12-06 18:46, hash: a95bf1ac01, type: release

For some reason, first output seems to be the third in the outputs list. ``` tree.links.new(na.outputs[2], nb.inputs["Surface"]) ``` And for the inputs, although the first socket is index 0 (correct), second and third input is index 6 and 7, respectively) ``` tree.links.new(na.outputs[2], nc.inputs[0]) # Factor tree.links.new(na.outputs[2], nc.inputs[6]) # A tree.links.new(na.outputs[2], nc.inputs[7]) # B ``` And I agree, this doesn't seem normal. **EDIT**: Above was observed in Blender version: 3.4.0, branch: blender-v3.4-release, commit date: 2022-12-06 18:46, hash: a95bf1ac01be, type: release

Added subscribers: @CharlieJolly, @deadpin

Added subscribers: @CharlieJolly, @deadpin

Changed status from 'Needs Triage' to: 'Needs Developer To Reproduce'

Changed status from 'Needs Triage' to: 'Needs Developer To Reproduce'

This is because you're connecting the wrong sockets (see below). The Mix node now hosts several different variants now, and the sockets will change depending on which data type and blend type is specified -- you can see this by enabling Python tooltips and hovering over the fields in question.

image.png

CC @CharlieJolly I'm not sure there's a good place to document how the sockets change but the current chart looks like the following - did I get these right?:

Data Type Output Socket index Input Sockets indices
Float 0 0 factor, 2 A, 3 B
Vector 1 0 factor, 1 non-uniform factor, 4 A, 5 B
Color 2 0 factor, 6 A, 7 B
This is because you're connecting the wrong sockets (see below). The Mix node now hosts several different variants now, and the sockets will change depending on which data type and blend type is specified -- you can see this by enabling Python tooltips and hovering over the fields in question. ![image.png](https://archive.blender.org/developer/F14082087/image.png) CC @CharlieJolly I'm not sure there's a good place to document how the sockets change but the current chart looks like the following - did I get these right?: | Data Type | Output Socket index | Input Sockets indices | | -- | -- | -- | | Float | 0 | 0 factor, 2 A, 3 B | | Vector | 1 | 0 factor, 1 non-uniform factor, 4 A, 5 B | | Color | 2 | 0 factor, 6 A, 7 B |
Author

Oh, that makes totally sense ! Thanks a lot @deadpin and sorry for that false report !

Oh, that makes totally sense ! Thanks a lot @deadpin and sorry for that false report !

Added subscriber: @mod_moder

Added subscriber: @mod_moder

Now changing the mode of operation and data type is just toggling the visibility of a bunch of sockets.
However, work is already underway to fix this.
Concretely, at the moment, Hans is verifying the addition of dynamic declarations https://developer.blender.org/diffusion/B/history/temp-nodes-group-declarations/source/blender/
This does not specifically fix your problem, as it is about different sockets for different modes of operation, but not types.
But this is current progress in this regard.

Now changing the mode of operation and data type is just toggling the visibility of a bunch of sockets. However, work is already underway to fix this. Concretely, at the moment, Hans is verifying the addition of dynamic declarations https://developer.blender.org/diffusion/B/history/temp-nodes-group-declarations/source/blender/ This does not specifically fix your problem, as it is about different sockets for different modes of operation, but not types. But this is current progress in this regard.

So for now, this is how socket addressing works.
But it will be fixed someday.
For now, you should only index the sockets that are visible.

So for now, this is how socket addressing works. But it will be fixed someday. For now, you should only index the sockets that are visible.

Added subscriber: @bigmark

Added subscriber: @bigmark
Member

In #103395#1464207, @deadpin wrote:
This is because you're connecting the wrong sockets (see below). The Mix node now hosts several different variants now, and the sockets will change depending on which data type and blend type is specified -- you can see this by enabling Python tooltips and hovering over the fields in question.

image.png

CC @CharlieJolly I'm not sure there's a good place to document how the sockets change but the current chart looks like the following - did I get these right?:
| Data Type | Output Socket index | Input Sockets indices |
| Float | 0 | 0 factor, 2 A, 3 B |
| Vector | 1 | 0 factor, 1 non-uniform factor, 4 A, 5 B |
| Color | 2 | 0 factor, 6 A, 7 B |

@deadpin yes that's right. Each data type has a different selection of sockets. It's probably worth adding a note on the documentation.

> In #103395#1464207, @deadpin wrote: > This is because you're connecting the wrong sockets (see below). The Mix node now hosts several different variants now, and the sockets will change depending on which data type and blend type is specified -- you can see this by enabling Python tooltips and hovering over the fields in question. > > ![image.png](https://archive.blender.org/developer/F14082087/image.png) > > CC @CharlieJolly I'm not sure there's a good place to document how the sockets change but the current chart looks like the following - did I get these right?: > | Data Type | Output Socket index | Input Sockets indices | > | Float | 0 | 0 factor, 2 A, 3 B | > | Vector | 1 | 0 factor, 1 non-uniform factor, 4 A, 5 B | > | Color | 2 | 0 factor, 6 A, 7 B | @deadpin yes that's right. Each data type has a different selection of sockets. It's probably worth adding a note on the documentation.

I'm not going to say how long it will take to add new ways to define different types of sockets.
But, probably, the mention in the documentation will only be relevant for this - the next versions (if not even faster)

I'm not going to say how long it will take to add new ways to define different types of sockets. But, probably, the mention in the documentation will only be relevant for this - the next versions (if not even faster)
Iliya Katushenock changed title from Material : connect Mix nodes with python fail to Node: Incorrect node socket indexing when connecting with python 2022-12-22 12:39:14 +01:00
Author

A note in the documentation would definitely help in the long run, but since this is such a simple operation I'm not sure I'll go and look into the doc ...
I'm not sure that a lot of nodes act that way either, that's part of the confusion.

Would having an error message make sense ? In the link operator, adding an option (off by default) to do the connection even if sockets aren't visible,
and by default displaying an error message when that fails ?

Just my two cents, at least it's easy to remember once you know, and I'll do my best to pass that torch to others if/when needed !

A note in the documentation would definitely help in the long run, but since this is such a simple operation I'm not sure I'll go and look into the doc ... I'm not sure that a lot of nodes act that way either, that's part of the confusion. Would having an error message make sense ? In the link operator, adding an option (off by default) to do the connection even if sockets aren't visible, and by default displaying an error message when that fails ? Just my two cents, at least it's easy to remember once you know, and I'll do my best to pass that torch to others if/when needed !

The ability to connect sockets that have been made invisible should remain, I guess

The ability to connect sockets that have been made invisible should remain, I guess

Added subscriber: @timknip

Added subscriber: @timknip

Added subscriber: @Human_Robot

Added subscriber: @Human_Robot

Added subscribers: @peterf-2, @LazyDodo, @JulienDuroure

Added subscribers: @peterf-2, @LazyDodo, @JulienDuroure
Philipp Oeser removed the
Interest
Nodes & Physics
label 2023-02-10 08:43:17 +01:00
Iliya Katushenock added
Status
Confirmed
and removed
Status
Needs Info from Developers
labels 2023-02-13 17:25:38 +01:00

just to add maybe it helps, when the mix node is set to float it works, only on color and vector it does not work

just to add maybe it helps, when the mix node is set to float it works, only on color and vector it does not work

@MarioTovirac Is not a bug, try Result_Vector

@MarioTovirac Is not a bug, try `Result_Vector`
Blender Bot added
Status
Archived
and removed
Status
Confirmed
labels 2023-04-11 13:19:24 +02:00
Iliya Katushenock added this to the Nodes & Physics project 2023-04-11 13:19:44 +02:00

@MarioTovirac Is not a bug, try Result_Vector

its not a bug that you cant call them by key because you used the same key for 3 different sockets? Ok, if its not a bug, its just terrible UI/API writing. Just put the type in the socket name.

> @MarioTovirac Is not a bug, try `Result_Vector` its not a bug that you cant call them by key because you used the same key for 3 different sockets? Ok, if its not a bug, its just terrible UI/API writing. Just put the type in the socket name.

Its still not mentioned in the documentation either.

Its still not mentioned in the documentation either.
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 Assignees
8 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#103395
No description provided.