Regression: Can't make node tree links in Python script #113106

Closed
opened 2023-10-01 08:31:39 +02:00 by Mingfen Wang · 9 comments

System Information
Operating system: macOS-14.0-arm64-arm-64bit 64 Bits
Graphics card: Metal API Apple M1 1.2

Blender Version
Broken: 4.0.0 Beta, branch: blender-v4.0-release, commit date: 2023-09-27 23:25, hash: 13f5879e3c61
Worked: v3.6.4

Short description of error
I can't generate node tree link for 'ShaderNodeMix' node by Python script.

For example, ob is the material, bsdf is the 'Principled BSDF' node, mix_rgb_node is the 'ShaderNodeMix' node, and texImage is the 'ShaderNodeTexImage' node, if I run these two lines, it should create a link from the output of the mix_rgb_node to the 'Base Color' input of the bsdf node, and create a link from the output of texImage to the first or the second input of mix_rgb_node, but in v4.0 beta, nothing happen.

ob.node_tree.links.new(bsdf.inputs['Base Color'], mix_rgb_node.outputs['Result'])

ob.node_tree.links.new(mix_rgb_node.inputs['A'], texImage.outputs['Color'])
or
ob.node_tree.links.new(mix_rgb_node.inputs['B'], texImage.outputs['Color'])

Exact steps for others to reproduce the error
Open provided file and run script.
Files with legacy mix node are working correct.

**System Information** Operating system: macOS-14.0-arm64-arm-64bit 64 Bits Graphics card: Metal API Apple M1 1.2 **Blender Version** Broken: 4.0.0 Beta, branch: blender-v4.0-release, commit date: 2023-09-27 23:25, hash: `13f5879e3c61` Worked: v3.6.4 **Short description of error** I can't generate node tree link for 'ShaderNodeMix' node by Python script. For example, ob is the material, bsdf is the 'Principled BSDF' node, mix_rgb_node is the 'ShaderNodeMix' node, and texImage is the 'ShaderNodeTexImage' node, if I run these two lines, it should create a link from the output of the mix_rgb_node to the 'Base Color' input of the bsdf node, and create a link from the output of texImage to the first or the second input of mix_rgb_node, but in v4.0 beta, nothing happen. ```Py ob.node_tree.links.new(bsdf.inputs['Base Color'], mix_rgb_node.outputs['Result']) ob.node_tree.links.new(mix_rgb_node.inputs['A'], texImage.outputs['Color']) or ob.node_tree.links.new(mix_rgb_node.inputs['B'], texImage.outputs['Color']) ``` **Exact steps for others to reproduce the error** Open provided file and run script. Files with legacy mix node are working correct.
Mingfen Wang added the
Type
Report
Severity
Normal
Status
Needs Triage
labels 2023-10-01 08:31:40 +02:00
Mingfen Wang changed title from Fail to generate node tree link for 'ShaderNodeMix' node to Fail to generate node tree links for 'ShaderNodeMix' node by Python script 2023-10-01 09:00:53 +02:00
Richard Antalik changed title from Fail to generate node tree links for 'ShaderNodeMix' node by Python script to Regression: Can't make node tree links in Python script 2023-10-12 22:51:04 +02:00
Richard Antalik changed title from Regression: Can't make node tree links in Python script to Can't make node tree links in Python script 2023-10-12 22:53:44 +02:00
Richard Antalik removed the
Severity
High
label 2023-10-12 22:53:49 +02:00

Retracting high priority, since I can reproduce this in 3.6 @artgolf1000 can you provide sample file where it works in 3.6 version?

Retracting high priority, since I can reproduce this in 3.6 @artgolf1000 can you provide sample file where it works in 3.6 version?
Author

I'm using 'ShaderNodeMixRGB' instead of 'ShaderNodeMix' in Blender 3.6.4, so it works without bug.

I'm using 'ShaderNodeMixRGB' instead of 'ShaderNodeMix' in Blender 3.6.4, so it works without bug.
Iliya Katushenock added the
Interest
Python API
label 2023-10-13 09:00:01 +02:00

Can you upload the file that works?

Can you upload the file that works?
Author

Here is the file that works in Blender 3.6.4, the 'ShaderNodeMixRGB' node is created via Python script.

Here is the file that works in Blender 3.6.4, the 'ShaderNodeMixRGB' node is created via Python script.

Thanks for file. It seems to work in 4.0 too, but the issue seems to be new Mix node.

Thanks for file. It seems to work in 4.0 too, but the issue seems to be new Mix node.
Richard Antalik added the
Severity
High
label 2023-10-16 20:50:03 +02:00
Richard Antalik changed title from Can't make node tree links in Python script to Regression: Can't make node tree links in Python script 2023-10-16 20:50:11 +02:00
Member

I haven't tried to reproduce it yet, but can you check that you are trying to make a link to the correct socket? Note that there are multiple sockets with the same but different identifiers and types. We are working towards improving this situation with different sockets with the same name.

I haven't tried to reproduce it yet, but can you check that you are trying to make a link to the correct socket? Note that there are multiple sockets with the same but different identifiers and types. We are working towards improving this situation with different sockets with the same name.
Author

I remembered that it did not work when Blender 4.0 Beta is just out, so I have to change to the new node of the same name, but the legacy node works correctly in the latest build of Blender 4.0 Beta, all sockets can be linked correctly by Python script.

I remembered that it did not work when Blender 4.0 Beta is just out, so I have to change to the new node of the same name, but the legacy node works correctly in the latest build of Blender 4.0 Beta, all sockets can be linked correctly by Python script.
Member

Just looked into it again, the issue is indeed what I mentioned before, sorry for not being more clear.

This is not a bug but expected behavior. The behavior is a bit different than before, because the Mix node now supports different data types. All those data types have separate sockets. We are already working towards unifying these sockets into one (#113553).

Currently, when you say mix_rgb_node.outputs['Result'], you will get the float output of the node, but there is also e.g. a vector and color output with the same name. For historic reasons, using node.outputs['xxx'] uses the socket name instead of identifier. So currently, you need a different way to find the correct output socket that you want to link.

The script from your file can be fixed like this:

import bpy

tree = bpy.context.object.active_material.node_tree
bsdf = tree.nodes['Principled BSDF']
mix = tree.nodes['Mix']

def get_socket(sockets, identifier):
    for socket in sockets:
        if socket.identifier == identifier:
            return socket

tree.links.new(get_socket(mix.outputs, 'Result_Color'), bsdf.inputs['Base Color'])
Just looked into it again, the issue is indeed what I mentioned before, sorry for not being more clear. This is not a bug but expected behavior. The behavior is a bit different than before, because the Mix node now supports different data types. All those data types have separate sockets. We are already working towards unifying these sockets into one (#113553). Currently, when you say `mix_rgb_node.outputs['Result']`, you will get the float output of the node, but there is also e.g. a vector and color output with the same name. For historic reasons, using `node.outputs['xxx']` uses the socket name instead of identifier. So currently, you need a different way to find the correct output socket that you want to link. The script from your file can be fixed like this: ``` import bpy tree = bpy.context.object.active_material.node_tree bsdf = tree.nodes['Principled BSDF'] mix = tree.nodes['Mix'] def get_socket(sockets, identifier): for socket in sockets: if socket.identifier == identifier: return socket tree.links.new(get_socket(mix.outputs, 'Result_Color'), bsdf.inputs['Base Color']) ```
Blender Bot added
Status
Archived
and removed
Status
Confirmed
labels 2023-10-20 16:15:03 +02:00

Duplicate of #103395

Duplicate of https://projects.blender.org/blender/blender/issues/103395
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
Code Documentation
Interest
Collada
Interest
Compatibility
Interest
Compositing
Interest
Core
Interest
Cycles
Interest
Dependency Graph
Interest
Development Management
Interest
EEVEE
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 & 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
Viewport & EEVEE
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
Asset System
Module
Core
Module
Development Management
Module
Grease Pencil
Module
Modeling
Module
Nodes & Physics
Module
Pipeline & IO
Module
Platforms, Builds & Tests
Module
Python API
Module
Render & Cycles
Module
Sculpt, Paint & Texture
Module
Triaging
Module
User Interface
Module
VFX & Video
Module
Viewport & EEVEE
Platform
FreeBSD
Platform
Linux
Platform
macOS
Platform
Windows
Severity
High
Severity
Low
Severity
Normal
Severity
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#113106
No description provided.