Python: Expose NodeLink.multi_input_socket_index
#115249
No reviewers
Labels
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, 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
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
Core
Module
Development Management
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
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
3 Participants
Notifications
Due Date
No due date set.
Dependencies
No dependencies set.
Reference: blender/blender#115249
Loading…
Reference in New Issue
Block a user
No description provided.
Delete Branch "Som1Lse/blender:main"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
This exposes
NodeLink.multi_input_socket_index
as a readonly property,along with a
swap_multi_input_socket_index
function that provides asafe and composable way to change it from Python.
Additionally this property is used in
NodeSocket.links
to sort thereturned tuple for input sockets.
This fixes a bug in Node Wrangler, where resetting nodes could change
the order of links.
This allows addons to read and reorder inputs to multi socket nodes,
functionality that was previously missing and could only be done from
C++, despite not being an uncommon operation.
First pull request, let me know if there is stuff I can improve.
Problem being addressed
Currently addons have no way of knowing the order of links to multi input socket nodes. For most nodes this doesn't matter but for Join Strings, it does. This means any operations that must preserve these cannot correctly be implemented by addons, and must be implemented in C++. Examples of this are Make Group, Duplicate and Node Wrangler's Reset Node.
What I've done
This exposes
NodeLink.multi_input_socket_index
to addons as a read-only property, and aswap_multi_input_socket_index
function that swaps the index with that of another link, which provides a safe and composable interface for reordering links.It is used by the
NodeSocket.links
property to sort links for input sockets. This makes the order reliable and meaning for addons, and incidentally fixes Node Wrangler's Reset Node operator, and possibly other addons.Alternatives considered
Seeing as this solution directly matches the representation of
bNodeLink
there isn't much room for design space without completely redesigning how links work.I did consider using shorter names, but I consider this to be an advanced feature, and so I decided to stick with the longer name used in C++.
Limitations
The API is very simple. While operations like move/rotate/sort can be implemented on top of swap in Python, it will not be as efficient as modifying
multi_input_socket_index
directly.Things I didn't do
I haven't written any tests for the code, and I didn't look into it. If there is a good example of writing automated tests for the Python API I'll gladly write some.
The documentation is also fairly rudimentary. I would definitely welcome comments here.
09680ce8a3
to1cb16fba70
What's with this PR?
I messed up the commits when I did a force push, so I closed it. There wasn't much interest before so I didn't get around to resubmitting it.
If there's a way to fix the commit history easily, I'll can do that, otherwise, I'll just open a new PR. I can format it better that way too, since the wiki is actually up now.
Not sure if there is any issues
@ -1232,0 +1228,4 @@
links = (link for link in self.id_data.links
if self in (link.from_socket, link.to_socket))
if not self.is_output:
If
statement should not be necessary, this collection is will have0
/1
sizes in this case.Output sockets can always have > 1 links.
The check is there because I don't want to sort links from output by the input sockets they're connected to, as this is really unintuitive.
Here's an example. (Link to image) First
AD
is created, thenAC
.A.links
is[AD, AC]
becauseAC.multi_input_socket_index == AD.multi_input_socket_index == 0
. After movingAD
(or inserting a link above it), we haveAC.multi_input_socket_index < AD.multi_input_socket_index
andA.links
becomes[AC, AD]
.Ah, multiple output links, yeah..
Closing in favor of #118987. Thanks for the patch.
Pull request closed