nodebpy 0.10.1__tar.gz → 0.11.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (74) hide show
  1. nodebpy-0.11.0/PKG-INFO +157 -0
  2. nodebpy-0.11.0/README.md +143 -0
  3. {nodebpy-0.10.1 → nodebpy-0.11.0}/pyproject.toml +5 -6
  4. {nodebpy-0.10.1 → nodebpy-0.11.0}/src/nodebpy/__init__.py +2 -2
  5. {nodebpy-0.10.1 → nodebpy-0.11.0}/src/nodebpy/builder/__init__.py +3 -0
  6. {nodebpy-0.10.1 → nodebpy-0.11.0}/src/nodebpy/builder/accessor.py +26 -4
  7. {nodebpy-0.10.1 → nodebpy-0.11.0}/src/nodebpy/builder/mixins.py +28 -25
  8. {nodebpy-0.10.1 → nodebpy-0.11.0}/src/nodebpy/builder/node.py +30 -3
  9. {nodebpy-0.10.1 → nodebpy-0.11.0}/src/nodebpy/builder/socket.py +405 -51
  10. {nodebpy-0.10.1 → nodebpy-0.11.0}/src/nodebpy/builder/tree.py +57 -42
  11. nodebpy-0.11.0/src/nodebpy/diagram.py +139 -0
  12. {nodebpy-0.10.1 → nodebpy-0.11.0}/src/nodebpy/nodes/compositor/__init__.py +18 -0
  13. {nodebpy-0.10.1 → nodebpy-0.11.0}/src/nodebpy/nodes/compositor/converter.py +188 -0
  14. {nodebpy-0.10.1 → nodebpy-0.11.0}/src/nodebpy/nodes/compositor/filter.py +67 -18
  15. {nodebpy-0.10.1 → nodebpy-0.11.0}/src/nodebpy/nodes/compositor/input.py +50 -116
  16. {nodebpy-0.10.1 → nodebpy-0.11.0}/src/nodebpy/nodes/compositor/manual.py +3 -1
  17. {nodebpy-0.10.1 → nodebpy-0.11.0}/src/nodebpy/nodes/geometry/__init__.py +26 -0
  18. {nodebpy-0.10.1 → nodebpy-0.11.0}/src/nodebpy/nodes/geometry/converter.py +836 -14
  19. {nodebpy-0.10.1 → nodebpy-0.11.0}/src/nodebpy/nodes/geometry/geometry.py +201 -79
  20. {nodebpy-0.10.1 → nodebpy-0.11.0}/src/nodebpy/nodes/geometry/grid.py +864 -57
  21. nodebpy-0.11.0/src/nodebpy/nodes/geometry/groups.py +205 -0
  22. {nodebpy-0.10.1 → nodebpy-0.11.0}/src/nodebpy/nodes/geometry/input.py +81 -0
  23. {nodebpy-0.10.1 → nodebpy-0.11.0}/src/nodebpy/nodes/geometry/interface.py +11 -0
  24. {nodebpy-0.10.1 → nodebpy-0.11.0}/src/nodebpy/nodes/geometry/manual.py +545 -419
  25. {nodebpy-0.10.1 → nodebpy-0.11.0}/src/nodebpy/nodes/geometry/vector.py +8 -0
  26. {nodebpy-0.10.1 → nodebpy-0.11.0}/src/nodebpy/nodes/shader/__init__.py +6 -0
  27. {nodebpy-0.10.1 → nodebpy-0.11.0}/src/nodebpy/nodes/shader/input.py +88 -0
  28. {nodebpy-0.10.1 → nodebpy-0.11.0}/src/nodebpy/nodes/shader/manual.py +2 -1
  29. {nodebpy-0.10.1 → nodebpy-0.11.0}/src/nodebpy/nodes/shader/vector.py +20 -0
  30. {nodebpy-0.10.1 → nodebpy-0.11.0}/src/nodebpy/types.py +4 -0
  31. nodebpy-0.10.1/PKG-INFO +0 -154
  32. nodebpy-0.10.1/README.md +0 -141
  33. nodebpy-0.10.1/src/nodebpy/nodes/geometry/groups.py +0 -104
  34. nodebpy-0.10.1/src/nodebpy/screenshot.py +0 -260
  35. {nodebpy-0.10.1 → nodebpy-0.11.0}/src/nodebpy/arrange.py +0 -0
  36. {nodebpy-0.10.1 → nodebpy-0.11.0}/src/nodebpy/builder/_registry.py +0 -0
  37. {nodebpy-0.10.1 → nodebpy-0.11.0}/src/nodebpy/builder/_utils.py +0 -0
  38. {nodebpy-0.10.1 → nodebpy-0.11.0}/src/nodebpy/builder/interface.py +0 -0
  39. {nodebpy-0.10.1 → nodebpy-0.11.0}/src/nodebpy/lib/nodearrange/__init__.py +0 -0
  40. {nodebpy-0.10.1 → nodebpy-0.11.0}/src/nodebpy/lib/nodearrange/arrange/graph.py +0 -0
  41. {nodebpy-0.10.1 → nodebpy-0.11.0}/src/nodebpy/lib/nodearrange/arrange/ordering.py +0 -0
  42. {nodebpy-0.10.1 → nodebpy-0.11.0}/src/nodebpy/lib/nodearrange/arrange/ranking.py +0 -0
  43. {nodebpy-0.10.1 → nodebpy-0.11.0}/src/nodebpy/lib/nodearrange/arrange/realize.py +0 -0
  44. {nodebpy-0.10.1 → nodebpy-0.11.0}/src/nodebpy/lib/nodearrange/arrange/stacking.py +0 -0
  45. {nodebpy-0.10.1 → nodebpy-0.11.0}/src/nodebpy/lib/nodearrange/arrange/structs.py +0 -0
  46. {nodebpy-0.10.1 → nodebpy-0.11.0}/src/nodebpy/lib/nodearrange/arrange/sugiyama.py +0 -0
  47. {nodebpy-0.10.1 → nodebpy-0.11.0}/src/nodebpy/lib/nodearrange/arrange/x_coords.py +0 -0
  48. {nodebpy-0.10.1 → nodebpy-0.11.0}/src/nodebpy/lib/nodearrange/arrange/y_coords.py +0 -0
  49. {nodebpy-0.10.1 → nodebpy-0.11.0}/src/nodebpy/lib/nodearrange/config.py +0 -0
  50. {nodebpy-0.10.1 → nodebpy-0.11.0}/src/nodebpy/lib/nodearrange/utils.py +0 -0
  51. {nodebpy-0.10.1 → nodebpy-0.11.0}/src/nodebpy/nodes/__init__.py +0 -0
  52. {nodebpy-0.10.1 → nodebpy-0.11.0}/src/nodebpy/nodes/compositor/color.py +0 -0
  53. {nodebpy-0.10.1 → nodebpy-0.11.0}/src/nodebpy/nodes/compositor/distort.py +0 -0
  54. {nodebpy-0.10.1 → nodebpy-0.11.0}/src/nodebpy/nodes/compositor/group.py +0 -0
  55. {nodebpy-0.10.1 → nodebpy-0.11.0}/src/nodebpy/nodes/compositor/interface.py +0 -0
  56. {nodebpy-0.10.1 → nodebpy-0.11.0}/src/nodebpy/nodes/compositor/matte.py +0 -0
  57. {nodebpy-0.10.1 → nodebpy-0.11.0}/src/nodebpy/nodes/compositor/output.py +0 -0
  58. {nodebpy-0.10.1 → nodebpy-0.11.0}/src/nodebpy/nodes/compositor/vector.py +0 -0
  59. {nodebpy-0.10.1 → nodebpy-0.11.0}/src/nodebpy/nodes/geometry/attribute.py +0 -0
  60. {nodebpy-0.10.1 → nodebpy-0.11.0}/src/nodebpy/nodes/geometry/color.py +0 -0
  61. {nodebpy-0.10.1 → nodebpy-0.11.0}/src/nodebpy/nodes/geometry/group.py +0 -0
  62. {nodebpy-0.10.1 → nodebpy-0.11.0}/src/nodebpy/nodes/geometry/output.py +0 -0
  63. {nodebpy-0.10.1 → nodebpy-0.11.0}/src/nodebpy/nodes/geometry/texture.py +0 -0
  64. {nodebpy-0.10.1 → nodebpy-0.11.0}/src/nodebpy/nodes/geometry/zone.py +0 -0
  65. {nodebpy-0.10.1 → nodebpy-0.11.0}/src/nodebpy/nodes/shader/color.py +0 -0
  66. {nodebpy-0.10.1 → nodebpy-0.11.0}/src/nodebpy/nodes/shader/converter.py +0 -0
  67. {nodebpy-0.10.1 → nodebpy-0.11.0}/src/nodebpy/nodes/shader/grid.py +0 -0
  68. {nodebpy-0.10.1 → nodebpy-0.11.0}/src/nodebpy/nodes/shader/group.py +0 -0
  69. {nodebpy-0.10.1 → nodebpy-0.11.0}/src/nodebpy/nodes/shader/interface.py +0 -0
  70. {nodebpy-0.10.1 → nodebpy-0.11.0}/src/nodebpy/nodes/shader/output.py +0 -0
  71. {nodebpy-0.10.1 → nodebpy-0.11.0}/src/nodebpy/nodes/shader/script.py +0 -0
  72. {nodebpy-0.10.1 → nodebpy-0.11.0}/src/nodebpy/nodes/shader/shader.py +0 -0
  73. {nodebpy-0.10.1 → nodebpy-0.11.0}/src/nodebpy/nodes/shader/texture.py +0 -0
  74. {nodebpy-0.10.1 → nodebpy-0.11.0}/src/nodebpy/sockets.py +0 -0
@@ -0,0 +1,157 @@
1
+ Metadata-Version: 2.3
2
+ Name: nodebpy
3
+ Version: 0.11.0
4
+ Summary: Build nodes trees in Blender more elegantly with code
5
+ Author: Brady Johnston
6
+ Author-email: Brady Johnston <brady.johnston@me.com>
7
+ License: GPL-3.0-or-later
8
+ Requires-Dist: bpy>=5.1.0 ; extra == 'bpy'
9
+ Requires-Dist: networkx>=3.6.1 ; extra == 'networkx'
10
+ Requires-Python: >=3.13
11
+ Provides-Extra: bpy
12
+ Provides-Extra: networkx
13
+ Description-Content-Type: text/markdown
14
+
15
+ # nodebpy
16
+
17
+ [![Run
18
+ Tests](https://github.com/BradyAJohnston/nodebpy/actions/workflows/tests.yml/badge.svg)](https://github.com/BradyAJohnston/nodebpy/actions/workflows/tests.yml)
19
+ [![](https://codecov.io/gh/BradyAJohnston/nodebpy/graph/badge.svg?token=buThDQZUED)](https://codecov.io/gh/BradyAJohnston/nodebpy)
20
+
21
+ A package to build node trees in blender more elegantly with python code. Geometry Nodes, Shader Nodes and Compositor nodes are all fully supported. Look at the [documentation](https://bradyajohnston.github.io/nodebpy) for more examples.
22
+
23
+ ## Creating Nodes With Code
24
+
25
+ > A text-based version of nodes should bring the convenience of writing code with IDE auto-completion, type hinting, with overall compactness and readability, while staying as close as possible to what building a node tree via the GUI feels like.
26
+
27
+ ```python
28
+ from nodebpy import geometry as g
29
+
30
+ with g.tree("AnotherTree", collapse=True) as tree:
31
+ rotation = (
32
+ g.RandomValue.vector(min=-1, seed=2)
33
+ >> g.AlignRotationToVector()
34
+ >> g.RotateRotation(rotate_by=g.AxisAngleToRotation(angle=0.3))
35
+ )
36
+
37
+ _ = (
38
+ tree.inputs.integer("Count", 10)
39
+ >> g.Points(position=g.RandomValue.vector(min=-1))
40
+ >> g.InstanceOnPoints(instance=g.Cube(), rotation=rotation)
41
+ >> g.SetPosition(
42
+ position=g.Position() * 2.0 + (0, 0.2, 0.3),
43
+ offset=(0, 0, 0.1),
44
+ )
45
+ >> g.RealizeInstances()
46
+ >> g.InstanceOnPoints(g.Cube(), instance=...)
47
+ >> tree.outputs.geometry("Instances")
48
+ )
49
+ ```
50
+
51
+ ![](docs/images/paste-1.png)
52
+
53
+ Nodes are created by instantiating their classes. The node tree they are added to is determined by the context the code is executed in (while inside `with g.tree():`). The interface for the node tree is created with `tree.inputs` and `tree.inputs`, adding the sockets and returning the input or output socket for linking with other nodes.
54
+
55
+ Nodes are linked by overloading the `>>` operator, to link from the previous node on the left to the input on the right. Suitable socket pairs are automatically selected or explicitly supplied.
56
+
57
+ The layout / arrangement of the node tree is not important to Blender's evaluation of it - but an automatic layout algorithm is potentially applied upon exiting the node tree context.
58
+
59
+ ### `nodebpy` and the `>>` operator
60
+
61
+ In `nodebpy` we use the `>>` operator to link from one node or socket into another.
62
+ This should feel and behave much like the <kbd>Alt</kbd> + <kbd>Right Click</kbd> drag between nodes in [Node Wrangler](https://docs.blender.org/manual/en/latest/addons/node/node_wrangler.html). It will use some smart logic to match the most compatible sockets between the nodes, but if you ever want to be explicit you do so. The input and output sockets of a node are accessible as properties via the `i.*` and `o.*` prefixes, or you can use the `...` placeholder to specify the particular input to be user, or pass in the previous node as a named argument.
63
+
64
+ ```py
65
+ # vector output will be linked into the first vector input (position)
66
+ g.Vector() >> g.SetPosition()
67
+ # vector output will be linked into the offset input
68
+ g.Vector() >> g.SetPosition(offset=...)
69
+ g.SetPosition(offset=g.Vector())
70
+ ```
71
+
72
+ The `>>` operator will always look for the _most_ compatible sockets first (matching data types) before looking for other compatible but not identical socket data types to link.
73
+ If a compatible match can't be found an error _will_ be thrown.
74
+
75
+ ### Contexts
76
+
77
+ What node tree or node tree interface we are currently editing is determined based on contexts.
78
+ Instantiating a node class outside of a tree context will throw an error. The easiest way to enter and exit a tree context is to use the `with` statement.
79
+
80
+ Each time you instantiate a node class, a new node will be created and added to the current tree.
81
+ If these nodes are given as arguments to other nodes or used with the `>>` operator, they will be automatically linked to the appropriate sockets.
82
+
83
+ ## Nodes
84
+
85
+ Documentation for all of the nodes can be found in the [API Reference](https://bradyajohnston.github.io/nodebpy/reference/). This is mostly built automatically from the existing Blender node classes.
86
+
87
+ Every node has all of it's input sockets and enum options exposed as arguments to the class constructor. Input sockets are prefixed with `.i.*` and output sockets are prefixed with `.o.*`. Properties that aren't exposed as sockets are available as class properties. Many properties are also available as class methods for convenience when constructing.
88
+
89
+ The basic math operators also automatically add relevant nodes with their operations and values set.
90
+
91
+ ```py
92
+ # operation is exposed as a property
93
+ math = g.Math(1.0, 2.0, operation='ADD')
94
+ math.operation = "SUBTRACT"
95
+
96
+ # operation can be chose as a class method
97
+ math = g.Math.subtract(1.0, 2.0)
98
+ math = g.Value(1.0) - 2.0
99
+ math = g.Math.add(1.0, 2.0)
100
+ math = g.Value(1.0) + 2.0
101
+ # the 3.0 + 2.0 is evaluated as regular python code first,
102
+ # so the result with be a Math.add(g.Value(1.0), 5.0)
103
+ math = g.Value(1.0) 3.0 + 2.0
104
+
105
+ # these are equivalent, the g.Math.multiply is automatically added
106
+ g.Value(1.0) * 2
107
+ g.Math.multiply(g.Value(1.0), 2.0)
108
+ ```
109
+
110
+ # Design Considerations
111
+
112
+ The top priority of `nodebpy` has been type hinting and IDE auto-complete.
113
+ Typical tooling that supports autoring regular python code should also support the authoring of node trees.
114
+ Much like [`databpy`](https://github.com/BradyAJohnston/databpy), this started as an internal tool used inside of [`molecularnodes`](https://github.com/BradyAJohnston/molecularnodes) but has since been broken out into it's own separate project.
115
+ This projects is robustly typed and tested, with the intent that it can be used internally for multiple other add-ons and projects.
116
+
117
+ - Node classes are named after nodes 'Random Value' -> `RandomValue()`
118
+ - Node 'subtypes' and methods should be accessible via dot (`.`) for easier IDE auto-complete and authoring:
119
+ - `RandomValue(data_type="FLOAT_VECTOR")` -> `RandomValue.vector()`
120
+ - Node properties are available on the top level, with inputs and outputs available behind `.i.*` and `.o.*` accessors
121
+ - Inputs and outputs from a node are prefixed with `i.*` and `o.*`:
122
+ - `AccumulateField().o.total` returns the output `Total` socket
123
+ - `AccumulateField().i.value` returns the input `Value` socket
124
+
125
+ ## Building
126
+
127
+ Most of the code for classes are generated automatically with the `generate.py` script.
128
+ Some nodes are manually specified in the `src/nodebpy/nodes/geometry/manual.py` if they require special handling.
129
+
130
+ Run the build & format script as such:
131
+
132
+ ```bash
133
+ uv run generate.py && uvx ruff format && uvx ruff check --fix
134
+ ```
135
+
136
+ ## Other Projects
137
+
138
+ There are several other notable projects which have also attempted interfacing with node trees via code. They mostly fit into two categories of either storing & retrieving node trees via code (`.json` or the `bpy` API), or authoring of node trees with custom API and syntax. This project mostly fits in to the latter category.
139
+
140
+
141
+
142
+ ### Storing node trees as code:
143
+ Converting node trees to the python API calls or `.json` is great to have a robust storage method, but this approach falls down in human authorability / readability. These projects are great for storage but less useful when wanting to write / generate node trees froms scratch.
144
+
145
+ - [NodeToPython](https://github.com/BrendanParmer/NodeToPython)
146
+ - [TreeClipper](https://github.com/Algebraic-UG/tree_clipper) (used by this project for running tests & snapshots)
147
+
148
+ ### Authoring node trees with code:
149
+ Two previous projects have made similar approaches to authoring node trees. `geometry-script` also auto-generated most of it's type hinting, code and docs. It uses the approach of method chaining with the `.` operator, but obfuscates some of the non-linear way of building node trees.
150
+
151
+ The other project `geonodes` uses a similar context system for creating and authoring node trees, but doesn't use the same method of exposing each individual node as it's own class that `nodebpy` does.
152
+
153
+ I personally found both of their APIs to _not quite_ fit how I wanted to work, leading to the creation of `nodebpy`.
154
+ In comparison, this project is also the only one that is also distributed on `PyPi` and insallable via `pip` for easier use in other projects.
155
+
156
+ - [geometry-script](https://github.com/carson-katri/geometry-script),
157
+ - [geonodes](https://github.com/al1brn/geonodes)
@@ -0,0 +1,143 @@
1
+ # nodebpy
2
+
3
+ [![Run
4
+ Tests](https://github.com/BradyAJohnston/nodebpy/actions/workflows/tests.yml/badge.svg)](https://github.com/BradyAJohnston/nodebpy/actions/workflows/tests.yml)
5
+ [![](https://codecov.io/gh/BradyAJohnston/nodebpy/graph/badge.svg?token=buThDQZUED)](https://codecov.io/gh/BradyAJohnston/nodebpy)
6
+
7
+ A package to build node trees in blender more elegantly with python code. Geometry Nodes, Shader Nodes and Compositor nodes are all fully supported. Look at the [documentation](https://bradyajohnston.github.io/nodebpy) for more examples.
8
+
9
+ ## Creating Nodes With Code
10
+
11
+ > A text-based version of nodes should bring the convenience of writing code with IDE auto-completion, type hinting, with overall compactness and readability, while staying as close as possible to what building a node tree via the GUI feels like.
12
+
13
+ ```python
14
+ from nodebpy import geometry as g
15
+
16
+ with g.tree("AnotherTree", collapse=True) as tree:
17
+ rotation = (
18
+ g.RandomValue.vector(min=-1, seed=2)
19
+ >> g.AlignRotationToVector()
20
+ >> g.RotateRotation(rotate_by=g.AxisAngleToRotation(angle=0.3))
21
+ )
22
+
23
+ _ = (
24
+ tree.inputs.integer("Count", 10)
25
+ >> g.Points(position=g.RandomValue.vector(min=-1))
26
+ >> g.InstanceOnPoints(instance=g.Cube(), rotation=rotation)
27
+ >> g.SetPosition(
28
+ position=g.Position() * 2.0 + (0, 0.2, 0.3),
29
+ offset=(0, 0, 0.1),
30
+ )
31
+ >> g.RealizeInstances()
32
+ >> g.InstanceOnPoints(g.Cube(), instance=...)
33
+ >> tree.outputs.geometry("Instances")
34
+ )
35
+ ```
36
+
37
+ ![](docs/images/paste-1.png)
38
+
39
+ Nodes are created by instantiating their classes. The node tree they are added to is determined by the context the code is executed in (while inside `with g.tree():`). The interface for the node tree is created with `tree.inputs` and `tree.inputs`, adding the sockets and returning the input or output socket for linking with other nodes.
40
+
41
+ Nodes are linked by overloading the `>>` operator, to link from the previous node on the left to the input on the right. Suitable socket pairs are automatically selected or explicitly supplied.
42
+
43
+ The layout / arrangement of the node tree is not important to Blender's evaluation of it - but an automatic layout algorithm is potentially applied upon exiting the node tree context.
44
+
45
+ ### `nodebpy` and the `>>` operator
46
+
47
+ In `nodebpy` we use the `>>` operator to link from one node or socket into another.
48
+ This should feel and behave much like the <kbd>Alt</kbd> + <kbd>Right Click</kbd> drag between nodes in [Node Wrangler](https://docs.blender.org/manual/en/latest/addons/node/node_wrangler.html). It will use some smart logic to match the most compatible sockets between the nodes, but if you ever want to be explicit you do so. The input and output sockets of a node are accessible as properties via the `i.*` and `o.*` prefixes, or you can use the `...` placeholder to specify the particular input to be user, or pass in the previous node as a named argument.
49
+
50
+ ```py
51
+ # vector output will be linked into the first vector input (position)
52
+ g.Vector() >> g.SetPosition()
53
+ # vector output will be linked into the offset input
54
+ g.Vector() >> g.SetPosition(offset=...)
55
+ g.SetPosition(offset=g.Vector())
56
+ ```
57
+
58
+ The `>>` operator will always look for the _most_ compatible sockets first (matching data types) before looking for other compatible but not identical socket data types to link.
59
+ If a compatible match can't be found an error _will_ be thrown.
60
+
61
+ ### Contexts
62
+
63
+ What node tree or node tree interface we are currently editing is determined based on contexts.
64
+ Instantiating a node class outside of a tree context will throw an error. The easiest way to enter and exit a tree context is to use the `with` statement.
65
+
66
+ Each time you instantiate a node class, a new node will be created and added to the current tree.
67
+ If these nodes are given as arguments to other nodes or used with the `>>` operator, they will be automatically linked to the appropriate sockets.
68
+
69
+ ## Nodes
70
+
71
+ Documentation for all of the nodes can be found in the [API Reference](https://bradyajohnston.github.io/nodebpy/reference/). This is mostly built automatically from the existing Blender node classes.
72
+
73
+ Every node has all of it's input sockets and enum options exposed as arguments to the class constructor. Input sockets are prefixed with `.i.*` and output sockets are prefixed with `.o.*`. Properties that aren't exposed as sockets are available as class properties. Many properties are also available as class methods for convenience when constructing.
74
+
75
+ The basic math operators also automatically add relevant nodes with their operations and values set.
76
+
77
+ ```py
78
+ # operation is exposed as a property
79
+ math = g.Math(1.0, 2.0, operation='ADD')
80
+ math.operation = "SUBTRACT"
81
+
82
+ # operation can be chose as a class method
83
+ math = g.Math.subtract(1.0, 2.0)
84
+ math = g.Value(1.0) - 2.0
85
+ math = g.Math.add(1.0, 2.0)
86
+ math = g.Value(1.0) + 2.0
87
+ # the 3.0 + 2.0 is evaluated as regular python code first,
88
+ # so the result with be a Math.add(g.Value(1.0), 5.0)
89
+ math = g.Value(1.0) 3.0 + 2.0
90
+
91
+ # these are equivalent, the g.Math.multiply is automatically added
92
+ g.Value(1.0) * 2
93
+ g.Math.multiply(g.Value(1.0), 2.0)
94
+ ```
95
+
96
+ # Design Considerations
97
+
98
+ The top priority of `nodebpy` has been type hinting and IDE auto-complete.
99
+ Typical tooling that supports autoring regular python code should also support the authoring of node trees.
100
+ Much like [`databpy`](https://github.com/BradyAJohnston/databpy), this started as an internal tool used inside of [`molecularnodes`](https://github.com/BradyAJohnston/molecularnodes) but has since been broken out into it's own separate project.
101
+ This projects is robustly typed and tested, with the intent that it can be used internally for multiple other add-ons and projects.
102
+
103
+ - Node classes are named after nodes 'Random Value' -> `RandomValue()`
104
+ - Node 'subtypes' and methods should be accessible via dot (`.`) for easier IDE auto-complete and authoring:
105
+ - `RandomValue(data_type="FLOAT_VECTOR")` -> `RandomValue.vector()`
106
+ - Node properties are available on the top level, with inputs and outputs available behind `.i.*` and `.o.*` accessors
107
+ - Inputs and outputs from a node are prefixed with `i.*` and `o.*`:
108
+ - `AccumulateField().o.total` returns the output `Total` socket
109
+ - `AccumulateField().i.value` returns the input `Value` socket
110
+
111
+ ## Building
112
+
113
+ Most of the code for classes are generated automatically with the `generate.py` script.
114
+ Some nodes are manually specified in the `src/nodebpy/nodes/geometry/manual.py` if they require special handling.
115
+
116
+ Run the build & format script as such:
117
+
118
+ ```bash
119
+ uv run generate.py && uvx ruff format && uvx ruff check --fix
120
+ ```
121
+
122
+ ## Other Projects
123
+
124
+ There are several other notable projects which have also attempted interfacing with node trees via code. They mostly fit into two categories of either storing & retrieving node trees via code (`.json` or the `bpy` API), or authoring of node trees with custom API and syntax. This project mostly fits in to the latter category.
125
+
126
+
127
+
128
+ ### Storing node trees as code:
129
+ Converting node trees to the python API calls or `.json` is great to have a robust storage method, but this approach falls down in human authorability / readability. These projects are great for storage but less useful when wanting to write / generate node trees froms scratch.
130
+
131
+ - [NodeToPython](https://github.com/BrendanParmer/NodeToPython)
132
+ - [TreeClipper](https://github.com/Algebraic-UG/tree_clipper) (used by this project for running tests & snapshots)
133
+
134
+ ### Authoring node trees with code:
135
+ Two previous projects have made similar approaches to authoring node trees. `geometry-script` also auto-generated most of it's type hinting, code and docs. It uses the approach of method chaining with the `.` operator, but obfuscates some of the non-linear way of building node trees.
136
+
137
+ The other project `geonodes` uses a similar context system for creating and authoring node trees, but doesn't use the same method of exposing each individual node as it's own class that `nodebpy` does.
138
+
139
+ I personally found both of their APIs to _not quite_ fit how I wanted to work, leading to the creation of `nodebpy`.
140
+ In comparison, this project is also the only one that is also distributed on `PyPi` and insallable via `pip` for easier use in other projects.
141
+
142
+ - [geometry-script](https://github.com/carson-katri/geometry-script),
143
+ - [geonodes](https://github.com/al1brn/geonodes)
@@ -1,13 +1,13 @@
1
1
  [project]
2
2
  name = "nodebpy"
3
- version = "0.10.1"
3
+ version = "0.11.0"
4
4
  description = "Build nodes trees in Blender more elegantly with code"
5
5
  readme = "README.md"
6
6
  authors = [
7
7
  { name = "Brady Johnston", email = "brady.johnston@me.com" }
8
8
  ]
9
- requires-python = ">=3.11"
10
- dependencies = []
9
+ requires-python = ">=3.13"
10
+ license = { text = "GPL-3.0-or-later" }
11
11
 
12
12
  [project.scripts]
13
13
  nodebpy = "nodebpy:main"
@@ -17,7 +17,7 @@ networkx = [
17
17
  "networkx>=3.6.1",
18
18
  ]
19
19
  bpy = [
20
- "bpy>=5.0.1",
20
+ "bpy>=5.1.0",
21
21
  ]
22
22
 
23
23
  [build-system]
@@ -28,12 +28,11 @@ build-backend = "uv_build"
28
28
  dev = [
29
29
  "ipython>=8.0.0",
30
30
  "networkx>=3.6.1",
31
- "numpy<2.0",
32
31
  "fake-bpy-module>=20260113",
33
32
  "jsondiff>=2.2.1",
34
33
  "pytest>=9.0.2",
35
34
  "pytest-cov>=7.0.0",
36
- "quarto-cli>=1.8.26",
35
+ "quarto-cli>=1.9",
37
36
  "quartodoc>=0.11.1",
38
37
  "ruff>=0.14.11",
39
38
  "syrupy>=5.0.0",
@@ -1,4 +1,4 @@
1
- from . import nodes, screenshot, sockets
1
+ from . import nodes, diagram, sockets
2
2
  from .builder import TreeBuilder, NodeGroupBuilder
3
3
  from .nodes import compositor, geometry, shader
4
4
 
@@ -8,7 +8,7 @@ __all__ = [
8
8
  "geometry",
9
9
  "shader",
10
10
  "sockets",
11
- "screenshot",
11
+ "diagram",
12
12
  "TreeBuilder",
13
13
  "NodeGroupBuilder",
14
14
  ]
@@ -35,6 +35,7 @@ from .socket import (
35
35
  CollectionSocket,
36
36
  ColorSocket,
37
37
  FloatSocket,
38
+ FontSocket,
38
39
  GeometrySocket,
39
40
  ImageSocket,
40
41
  IntegerSocket,
@@ -93,6 +94,7 @@ __all__ = [
93
94
  "MenuSocket",
94
95
  "GeometrySocket",
95
96
  "ObjectSocket",
97
+ "FontSocket",
96
98
  "MaterialSocket",
97
99
  "ImageSocket",
98
100
  "CollectionSocket",
@@ -120,6 +122,7 @@ __all__ = [
120
122
  "SocketMenu",
121
123
  "SocketObject",
122
124
  "SocketGeometry",
125
+ "SocketFont",
123
126
  "SocketCollection",
124
127
  "SocketImage",
125
128
  "SocketMaterial",
@@ -1,12 +1,17 @@
1
1
  from __future__ import annotations
2
2
 
3
- from typing import TYPE_CHECKING, Literal
3
+ from typing import TYPE_CHECKING, Literal, overload
4
4
 
5
5
  import bpy
6
6
  from bpy.types import NodeSocket
7
7
 
8
8
  from ._registry import _get_socket_linker
9
- from ._utils import SocketError, _allow_innactive_sockets, denormalize_name
9
+ from ._utils import (
10
+ SocketError,
11
+ _allow_innactive_sockets,
12
+ denormalize_name,
13
+ normalize_name,
14
+ )
10
15
 
11
16
  if TYPE_CHECKING:
12
17
  from .socket import Socket
@@ -43,6 +48,10 @@ class SocketAccessor:
43
48
  for candidate in (key, denorm):
44
49
  if candidate in ids:
45
50
  return ids.index(candidate)
51
+ # Normalized identifier match: 'value_001' matches identifier 'Value_001'
52
+ normalized_ids = [normalize_name(id) for id in ids]
53
+ if key in normalized_ids:
54
+ return normalized_ids.index(key)
46
55
  names = [s.name for s in self._collection]
47
56
  for key in (key, denorm):
48
57
  if key in names:
@@ -58,11 +67,24 @@ class SocketAccessor:
58
67
  f"{self._node.bl_idname}. Available sockets (id: name): {list(zip(ids, names))}"
59
68
  )
60
69
 
61
- def _get(self, key: str | int) -> "Socket":
70
+ @overload
71
+ def _get(self, key: slice) -> "list[Socket]": ...
72
+ @overload
73
+ def _get(self, key: str | int) -> "Socket": ...
74
+ def _get(self, key: str | int | slice) -> "Socket | list[Socket]":
62
75
  """Get a Socket for a socket by identifier, name, or index."""
76
+ if isinstance(key, slice):
77
+ return [
78
+ _get_socket_linker(self._collection[i])
79
+ for i in range(*key.indices(len(self._collection)))
80
+ ]
63
81
  return _get_socket_linker(self._collection[self._index(key)])
64
82
 
65
- def __getitem__(self, key: str | int) -> "Socket":
83
+ @overload
84
+ def __getitem__(self, key: slice) -> "list[Socket]": ...
85
+ @overload
86
+ def __getitem__(self, key: str | int) -> "Socket": ...
87
+ def __getitem__(self, key: str | int | slice) -> "Socket | list[Socket]":
66
88
  """Access by identifier, name, or integer index."""
67
89
  return self._get(key)
68
90
 
@@ -1,14 +1,17 @@
1
1
  from __future__ import annotations
2
2
 
3
3
  from types import EllipsisType
4
- from typing import TYPE_CHECKING, Any
4
+ from typing import TYPE_CHECKING, Any, TypeVar
5
5
 
6
6
  from bpy.types import NodeLink, NodeSocket
7
7
 
8
8
  from ._registry import _get_socket_linker
9
9
  from ._utils import SocketError, _resolve_promotion, _SocketLike
10
10
 
11
+ _RShiftT = TypeVar("_RShiftT")
12
+
11
13
  if TYPE_CHECKING:
14
+ from ..nodes.geometry import Compare, Math
12
15
  from ..types import InputLinkable
13
16
  from .node import BaseNode
14
17
  from .socket import Socket
@@ -26,7 +29,7 @@ class OperatorMixin:
26
29
 
27
30
  def _apply_math_operation(
28
31
  self, other: Any, operation: str, reverse: bool = False
29
- ) -> "BaseNode":
32
+ ) -> "Math":
30
33
  socket, other, reverse = _resolve_promotion(
31
34
  self._default_output_socket,
32
35
  other,
@@ -34,43 +37,43 @@ class OperatorMixin:
34
37
  )
35
38
  return _get_socket_linker(socket)._dispatch_math(other, operation, reverse)
36
39
 
37
- def __mul__(self, other: Any) -> "BaseNode":
40
+ def __mul__(self, other: Any) -> "Math":
38
41
  return self._apply_math_operation(other, "multiply")
39
42
 
40
- def __rmul__(self, other: Any) -> "BaseNode":
43
+ def __rmul__(self, other: Any) -> "Math":
41
44
  return self._apply_math_operation(other, "multiply", reverse=True)
42
45
 
43
- def __truediv__(self, other: Any) -> "BaseNode":
46
+ def __truediv__(self, other: Any) -> "Math":
44
47
  return self._apply_math_operation(other, "divide")
45
48
 
46
- def __rtruediv__(self, other: Any) -> "BaseNode":
49
+ def __rtruediv__(self, other: Any) -> "Math":
47
50
  return self._apply_math_operation(other, "divide", reverse=True)
48
51
 
49
- def __add__(self, other: Any) -> "BaseNode":
52
+ def __add__(self, other: Any) -> "Math":
50
53
  return self._apply_math_operation(other, "add")
51
54
 
52
- def __radd__(self, other: Any) -> "BaseNode":
55
+ def __radd__(self, other: Any) -> "Math":
53
56
  return self._apply_math_operation(other, "add", reverse=True)
54
57
 
55
- def __sub__(self, other: Any) -> "BaseNode":
58
+ def __sub__(self, other: Any) -> "Math":
56
59
  return self._apply_math_operation(other, "subtract")
57
60
 
58
- def __rsub__(self, other: Any) -> "BaseNode":
61
+ def __rsub__(self, other: Any) -> "Math":
59
62
  return self._apply_math_operation(other, "subtract", reverse=True)
60
63
 
61
- def __pow__(self, other: Any) -> "BaseNode":
64
+ def __pow__(self, other: Any) -> "Math":
62
65
  return self._apply_math_operation(other, "power")
63
66
 
64
- def __rpow__(self, other: Any) -> "BaseNode":
67
+ def __rpow__(self, other: Any) -> "Math":
65
68
  return self._apply_math_operation(other, "power", reverse=True)
66
69
 
67
- def __mod__(self, other: Any) -> "BaseNode":
70
+ def __mod__(self, other: Any) -> "Math":
68
71
  return self._apply_math_operation(other, "modulo")
69
72
 
70
- def __rmod__(self, other: Any) -> "BaseNode":
73
+ def __rmod__(self, other: Any) -> "Math":
71
74
  return self._apply_math_operation(other, "modulo", reverse=True)
72
75
 
73
- def __floordiv__(self, other: Any) -> "BaseNode":
76
+ def __floordiv__(self, other: Any) -> "Math":
74
77
  socket, other, reverse = _resolve_promotion(
75
78
  self._default_output_socket,
76
79
  other,
@@ -78,7 +81,7 @@ class OperatorMixin:
78
81
  )
79
82
  return _get_socket_linker(socket)._dispatch_floordiv(other, reverse)
80
83
 
81
- def __rfloordiv__(self, other: Any) -> "BaseNode":
84
+ def __rfloordiv__(self, other: Any) -> "Math":
82
85
  socket, other, reverse = _resolve_promotion(
83
86
  self._default_output_socket,
84
87
  other,
@@ -86,37 +89,37 @@ class OperatorMixin:
86
89
  )
87
90
  return _get_socket_linker(socket)._dispatch_floordiv(other, reverse)
88
91
 
89
- def __neg__(self) -> "BaseNode":
92
+ def __neg__(self) -> "Math":
90
93
  return _get_socket_linker(self._default_output_socket)._dispatch_unary( # type: ignore[attr-defined]
91
94
  "negate"
92
95
  )
93
96
 
94
- def __abs__(self) -> "BaseNode":
97
+ def __abs__(self) -> "Math":
95
98
  return _get_socket_linker(self._default_output_socket)._dispatch_unary( # type: ignore[attr-defined]
96
99
  "absolute"
97
100
  )
98
101
 
99
- def _apply_compare_operation(self, other: Any, operation: str) -> "BaseNode":
102
+ def _apply_compare_operation(self, other: Any, operation: str) -> "Math":
100
103
  return _get_socket_linker(self._default_output_socket)._dispatch_compare( # type: ignore[attr-defined]
101
104
  other, operation
102
105
  )
103
106
 
104
- def __lt__(self, other: Any) -> "BaseNode":
107
+ def __lt__(self, other: Any) -> "Compare":
105
108
  return self._apply_compare_operation(other, "less_than")
106
109
 
107
- def __gt__(self, other: Any) -> "BaseNode":
110
+ def __gt__(self, other: Any) -> "Compare":
108
111
  return self._apply_compare_operation(other, "greater_than")
109
112
 
110
- def __le__(self, other: Any) -> "BaseNode":
113
+ def __le__(self, other: Any) -> "Compare":
111
114
  return self._apply_compare_operation(other, "less_equal")
112
115
 
113
- def __ge__(self, other: Any) -> "BaseNode":
116
+ def __ge__(self, other: Any) -> "Compare":
114
117
  return self._apply_compare_operation(other, "greater_equal")
115
118
 
116
- def __eq__(self, other: Any) -> "BaseNode": # type: ignore[override]
119
+ def __eq__(self, other: Any) -> "Compare": # type: ignore[override]
117
120
  return self._apply_compare_operation(other, "equal")
118
121
 
119
- def __ne__(self, other: Any) -> "BaseNode": # type: ignore[override]
122
+ def __ne__(self, other: Any) -> "Compare": # type: ignore[override]
120
123
  return self._apply_compare_operation(other, "not_equal")
121
124
 
122
125
  def _apply_boolean_operation(self, other: Any, operation: str):
@@ -1,7 +1,7 @@
1
1
  from __future__ import annotations
2
2
 
3
3
  from abc import ABC, abstractmethod
4
- from typing import TYPE_CHECKING, Iterable, Literal
4
+ from typing import TYPE_CHECKING, Iterable, Literal, Self
5
5
 
6
6
  import bpy
7
7
  from bpy.types import Node, NodeSocket
@@ -25,7 +25,7 @@ class BaseNode(_NodeLike, OperatorMixin, LinkingMixin):
25
25
  _default_output_id: str | None = None
26
26
  _placeholder_inputs: list[str]
27
27
 
28
- def __init__(self):
28
+ def __init__(self, node: bpy.types.Node | None = None):
29
29
  tree = (
30
30
  TreeBuilder._tree_contexts[-1] if len(TreeBuilder._tree_contexts) else None
31
31
  )
@@ -39,7 +39,7 @@ class BaseNode(_NodeLike, OperatorMixin, LinkingMixin):
39
39
 
40
40
  self._tree = tree
41
41
  self._placeholder_inputs = []
42
- self.node: bpy.types.Node = self._tree.add(self.__class__._bl_idname)
42
+ self.node = node if node else self._tree.add(self.__class__._bl_idname)
43
43
 
44
44
  @property
45
45
  def tree(self) -> TreeBuilder:
@@ -71,6 +71,33 @@ class BaseNode(_NodeLike, OperatorMixin, LinkingMixin):
71
71
  socket = self.node.outputs[counter]
72
72
  return socket
73
73
 
74
+ @classmethod
75
+ def _from_node(cls, node: bpy.types.Node) -> Self:
76
+ builder = cls()
77
+ builder.tree.nodes.remove(builder.node)
78
+ builder.node = node
79
+ return builder
80
+
81
+ @classmethod
82
+ def _find_or_create_linked(cls, socket: NodeSocket) -> Self:
83
+ if socket.is_output:
84
+ if socket.links:
85
+ for link in socket.links:
86
+ assert link.to_node
87
+ if link.to_node.bl_idname == cls._bl_idname:
88
+ return cls._from_node(link.to_node)
89
+ return cls(socket)
90
+ else:
91
+ if socket.links:
92
+ for link in socket.links:
93
+ assert link.from_node
94
+ if link.from_node.bl_idname == cls._bl_idname:
95
+ return cls._from_node(link.from_node)
96
+
97
+ node = cls()
98
+ node >> socket
99
+ return node
100
+
74
101
  def _set_input_default_value(self, input, value):
75
102
  """Set the default value for an input socket, handling type conversions."""
76
103
  if (