nodebpy 0.1.0__tar.gz → 0.1.1__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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.3
2
2
  Name: nodebpy
3
- Version: 0.1.0
3
+ Version: 0.1.1
4
4
  Summary: Build nodes in Blender with code
5
5
  Author: Brady Johnston
6
6
  Author-email: Brady Johnston <brady.johnston@me.com>
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "nodebpy"
3
- version = "0.1.0"
3
+ version = "0.1.1"
4
4
  description = "Build nodes in Blender with code"
5
5
  readme = "README.md"
6
6
  authors = [
@@ -290,7 +290,14 @@ class NodeBuilder:
290
290
  # so instead we have to convert the identifier to an index and then lookup the socket
291
291
  # from the index instead
292
292
  input_ids = [input.identifier for input in self.node.inputs]
293
- return input_ids.index(identifier)
293
+ if identifier in input_ids:
294
+ idx = input_ids.index(identifier)
295
+ return idx
296
+ input_names = [input.name for input in self.node.inputs]
297
+ if identifier in input_names:
298
+ return input_names.index(identifier)
299
+
300
+ raise RuntimeError()
294
301
 
295
302
  def _output_idx(self, identifier: str) -> int:
296
303
  output_ids = [output.identifier for output in self.node.outputs]
@@ -298,7 +305,8 @@ class NodeBuilder:
298
305
 
299
306
  def _input(self, identifier: str) -> SocketLinker:
300
307
  """Input socket: Vector"""
301
- return SocketLinker(self.node.inputs[self._input_idx(identifier)])
308
+ input = self.node.inputs[self._input_idx(identifier)]
309
+ return SocketLinker(input)
302
310
 
303
311
  def _output(self, identifier: str) -> SocketLinker:
304
312
  """Output socket: Vector"""
@@ -336,7 +344,6 @@ class NodeBuilder:
336
344
  # we can also provide just a default value for the socket to take if we aren't
337
345
  # providing a socket to link with
338
346
  elif isinstance(value, (NodeBuilder, SocketNodeBuilder, NodeSocket, Node)):
339
- # print("Linking from", value, "to", name)
340
347
  self.link_from(value, name)
341
348
  else:
342
349
  if name in input_ids:
@@ -346,7 +353,7 @@ class NodeBuilder:
346
353
  input = self.node.inputs[name.replace("_", "").capitalize()]
347
354
  input.default_value = value
348
355
 
349
- def __rshift__(self, other: "NodeBuilder") -> "NodeBuilder":
356
+ def __rshift__(self, other: "NodeBuilder | SocketLinker") -> "NodeBuilder":
350
357
  """Chain nodes using >> operator. Links output to input.
351
358
 
352
359
  Usage:
@@ -362,19 +369,24 @@ class NodeBuilder:
362
369
  socket_out = self.node.outputs.get("Geometry") or self._default_output_socket
363
370
  other._from_socket = socket_out
364
371
 
365
- # Get target socket
366
- if other._link_target is not None:
367
- # Use specific target if set by ellipsis
368
- socket_in = self._get_input_socket_by_name(other, other._link_target)
372
+ if isinstance(other, SocketLinker):
373
+ socket_in = other.socket
369
374
  else:
370
- # Default behavior - prefer Geometry, fall back to default
371
- socket_in = other.node.inputs.get("Geometry") or other._default_input_socket
375
+ # Get target socket
376
+ if other._link_target is not None:
377
+ # Use specific target if set by ellipsis
378
+ socket_in = self._get_input_socket_by_name(other, other._link_target)
379
+ else:
380
+ # Default behavior - prefer Geometry, fall back to default
381
+ socket_in = (
382
+ other.node.inputs.get("Geometry") or other._default_input_socket
383
+ )
372
384
 
373
- # If target socket already has a link and isn't multi-input, try next available socket
374
- if socket_in.links and not socket_in.is_multi_input:
375
- socket_in = (
376
- self._get_next_available_socket(socket_in, socket_out) or socket_in
377
- )
385
+ # If target socket already has a link and isn't multi-input, try next available socket
386
+ if socket_in.links and not socket_in.is_multi_input:
387
+ socket_in = (
388
+ self._get_next_available_socket(socket_in, socket_out) or socket_in
389
+ )
378
390
 
379
391
  self.tree.link(socket_out, socket_in)
380
392
  return other
@@ -508,6 +520,10 @@ class SocketLinker(NodeBuilder):
508
520
  def type(self) -> str:
509
521
  return self.socket.type
510
522
 
523
+ @property
524
+ def socket_name(self) -> str:
525
+ return self.socket.name
526
+
511
527
 
512
528
  class SocketNodeBuilder(NodeBuilder):
513
529
  """Special NodeBuilder for accessing specific sockets on input/output nodes."""
@@ -173,32 +173,6 @@ class String(NodeBuilder):
173
173
  self.node.string = value
174
174
 
175
175
 
176
- class Vector(NodeBuilder):
177
- """Provide a vector value that can be connected to other nodes in the tree"""
178
-
179
- name = "FunctionNodeInputVector"
180
- node: bpy.types.FunctionNodeInputVector
181
-
182
- def __init__(self, vector: float = 0.0, **kwargs):
183
- super().__init__()
184
- key_args = kwargs
185
- self.vector = vector
186
- self._establish_links(**key_args)
187
-
188
- @property
189
- def o_vector(self) -> bpy.types.NodeSocketVector:
190
- """Output socket: Vector"""
191
- return self._output("Vector")
192
-
193
- @property
194
- def vector(self) -> list[float, float, float]:
195
- return self.node.vector
196
-
197
- @vector.setter
198
- def vector(self, value: list[float, float, float]):
199
- self.node.vector = value
200
-
201
-
202
176
  class ForEachGeometryElementInput(NodeBuilder):
203
177
  """For Each Geometry Element Input node"""
204
178
 
@@ -20,6 +20,32 @@ from .types import LINKABLE, TYPE_INPUT_BOOLEAN, TYPE_INPUT_VECTOR, _AttributeDo
20
20
  _RANDOM_VALUE_DATA_TYPES = Literal["FLOAT", "INT", "BOOLEAN", "FLOAT_VECTOR"]
21
21
 
22
22
 
23
+ class Vector(NodeBuilder):
24
+ """Provide a vector value that can be connected to other nodes in the tree"""
25
+
26
+ name = "FunctionNodeInputVector"
27
+ node: bpy.types.FunctionNodeInputVector
28
+
29
+ def __init__(self, vector: list[float, float, float] | None = (0, 0, 0), **kwargs):
30
+ super().__init__()
31
+ key_args = kwargs
32
+ self.vector = vector
33
+ self._establish_links(**key_args)
34
+
35
+ @property
36
+ def o_vector(self) -> bpy.types.NodeSocketVector:
37
+ """Output socket: Vector"""
38
+ return self._output("Vector")
39
+
40
+ @property
41
+ def vector(self) -> list[float, float, float]:
42
+ return self.node.vector
43
+
44
+ @vector.setter
45
+ def vector(self, value: list[float, float, float]):
46
+ self.node.vector = value
47
+
48
+
23
49
  class RandomValue(NodeBuilder):
24
50
  """Random Value node"""
25
51
 
File without changes
File without changes
File without changes
File without changes