Add helper function to node_utils to create links to virtual sockets #105975

Merged
Hans Goudey merged 1 commits from pioverfour/blender:dp_node_utils_virtual_sockets into main 2023-04-12 14:18:43 +02:00
Member

Links created through the normal Python API are invalid since
7026096099. Before then, one could create links to or from virtual
sockets from Python (grayed out sockets in Group Input and Group
Output nodes), as is still possible in the GUI.

This is documented as an API change, and it broke at least Node
Wrangler, see blender/blender-addons#104470. Instead of just fixing that, let's introduce an
API to make this operation simpler.


This is what now happens with the normal API:
image

Links created through the normal Python API are invalid since 7026096099. Before then, one could create links to or from virtual sockets from Python (grayed out sockets in Group Input and Group Output nodes), as is still possible in the GUI. This is documented as an API change, and it broke at least Node Wrangler, see blender/blender-addons#104470. Instead of just fixing that, let's introduce an API to make this operation simpler. ----- This is what now happens with the normal API: ![image](/attachments/5fac5fa4-a518-45d3-97d6-2c845820b1ff)
Damien Picard added the
Module
Python API
Interest
Nodes & Physics
labels 2023-03-22 00:58:13 +01:00
Damien Picard changed title from WIP: Add helper function to node_utils to create links to virtual sockets to Add helper function to node_utils to create links to virtual sockets 2023-03-22 01:18:24 +01:00
Damien Picard requested review from Hans Goudey 2023-03-22 01:22:38 +01:00
Author
Member

@HooglyBoogly I’m assigning the review to you since it’s a followup to 7026096099 and we briefly discussed it in blender/blender-addons#104470, but feel free to assign to someone else.

@HooglyBoogly I’m assigning the review to you since it’s a followup to 7026096099 and we briefly discussed it in blender/blender-addons#104470, but feel free to assign to someone else.
Author
Member

Come to think of it, maybe this can still go into 3.5 so that scripters could fix their scripts more easily in this version?

Come to think of it, maybe this can still go into 3.5 so that scripters could fix their scripts more easily in this version?

Why not just have a utility to connect any 2 sockets?

Why not just have a utility to connect any 2 sockets?
Author
Member

Why not just have a utility to connect any 2 sockets?

That’s exactly what this does! If both sockets are regular ones, it just connects them, but it creates actual sockets if one or more is virtual.

> Why not just have a utility to connect any 2 sockets? That’s exactly what this does! If both sockets are regular ones, it just connects them, but it creates actual sockets if one or more is virtual.

Then maybe just connect_socket ?

Then maybe just `connect_socket` ?
Damien Picard force-pushed dp_node_utils_virtual_sockets from e349c77b50 to 8c66579a8d 2023-03-22 17:25:51 +01:00 Compare
Author
Member

connect_sockets sounds good. I improved the docstring to make it clearer why one may want to use this.

Also added print messages in some unsupported cases.

`connect_sockets` sounds good. I improved the docstring to make it clearer why one may want to use this. Also added print messages in some unsupported cases.
Damien Picard force-pushed dp_node_utils_virtual_sockets from 8c66579a8d to 56036448bc 2023-03-22 17:29:37 +01:00 Compare
Damien Picard force-pushed dp_node_utils_virtual_sockets from 56036448bc to 996e415bbc 2023-03-22 18:05:37 +01:00 Compare
Hans Goudey reviewed 2023-03-23 15:29:39 +01:00
Hans Goudey left a comment
Member

This looks reasonable, thanks for looking into it. Is it typical for functions like this to use print( for errors? That surprised me a bit.

This looks reasonable, thanks for looking into it. Is it typical for functions like this to use `print(` for errors? That surprised me a bit.
Author
Member

I don’t think it’s typical, but raising an error is too harsh, and failing silently, probably not enough. This is really for Python scripters and not for end-users.
In fact in a previous version there were exceptions, but I’d like this function to be a replacement for the native links.new(), which does handle some weird cases and fails silently in others.
Both Bastien and Campbell have used a few prints to report errors in bpy.utils and bpy_extras, that’s authority enough for me!

I don’t think it’s typical, but raising an error is too harsh, and failing silently, probably not enough. This is really for Python scripters and not for end-users. In fact in a previous version there were exceptions, but I’d like this function to be a replacement for the native `links.new()`, which does handle some weird cases and fails silently in others. Both Bastien and Campbell have used a few prints to report errors in `bpy.utils` and `bpy_extras`, that’s authority enough for me!
Hans Goudey approved these changes 2023-03-23 15:41:09 +01:00
Author
Member

Hi, do you think this can be merged?

Hi, do you think this can be merged?
Member

Ah, indeed! Sorry I forgot about this one!

Ah, indeed! Sorry I forgot about this one!
Hans Goudey merged commit 81815681d0 into main 2023-04-12 14:18:43 +02:00
Damien Picard deleted branch dp_node_utils_virtual_sockets 2023-04-12 14:19:14 +02:00
Random reviewed 2023-06-28 08:50:35 +02:00
@ -8,0 +22,4 @@
if input.is_output and not output.is_output:
input, output = output, input
input_node = output.node
First-time contributor

Probably it worth to mention that performance of the function is O(len(node_group.nodes)) because you call output.node. Also in some cases output.node can return None.

Probably it worth to mention that performance of the function is `O(len(node_group.nodes))` because you call `output.node`. Also in some cases `output.node` can return None.
Sign in to join this conversation.
No reviewers
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#105975
No description provided.