nodebpy 0.2.0__py3-none-any.whl → 0.2.1__py3-none-any.whl

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.
nodebpy/builder.py CHANGED
@@ -3,7 +3,7 @@ from __future__ import annotations
3
3
  from typing import TYPE_CHECKING, Any, ClassVar, Literal
4
4
 
5
5
  if TYPE_CHECKING:
6
- from .nodes.converter import Math, VectorMath
6
+ from .nodes import Math, VectorMath
7
7
 
8
8
  import arrangebpy
9
9
  import bpy
@@ -14,7 +14,7 @@ from bpy.types import (
14
14
  NodeSocket,
15
15
  )
16
16
 
17
- from .nodes.types import (
17
+ from .types import (
18
18
  LINKABLE,
19
19
  SOCKET_COMPATIBILITY,
20
20
  SOCKET_TYPES,
@@ -117,12 +117,10 @@ class TreeBuilder:
117
117
  just_added: "Node | None" = None
118
118
 
119
119
  def __init__(
120
- self, tree: "GeometryNodeTree | str | None" = None, arrange: bool = True
120
+ self, tree: GeometryNodeTree | str = "Geometry Nodes", arrange: bool = True
121
121
  ):
122
122
  if isinstance(tree, str):
123
123
  self.tree = bpy.data.node_groups.new(tree, "GeometryNodeTree")
124
- elif tree is None:
125
- self.tree = bpy.data.node_groups.new("GeometryNodeTree", "GeometryNodeTree")
126
124
  else:
127
125
  assert isinstance(tree, GeometryNodeTree)
128
126
  self.tree = tree
@@ -195,14 +193,16 @@ class TreeBuilder:
195
193
  link = self.tree.links.new(socket1, socket2, handle_dynamic_sockets=True)
196
194
 
197
195
  if any(socket.is_inactive for socket in [socket1, socket2]):
196
+ assert socket1.node
197
+ assert socket2.node
198
198
  # the warning message should report which sockets from which nodes were linked and which were innactive
199
199
  for socket in [socket1, socket2]:
200
200
  # we want to be loud about it if we end up linking an inactive socket to a node that is not a switch
201
- if socket.is_inactive and socket.node.bl_idname not in (
201
+ if socket.is_inactive and socket.node.bl_idname not in ( # type: ignore
202
202
  "GeometryNodeIndexSwitch",
203
203
  "GeometryNodeMenuSwitch",
204
204
  ):
205
- message = f"Socket {socket.name} from node {socket.node.name} is inactive."
205
+ message = f"Socket {socket.name} from node {socket.node.name} is inactive." # type: ignore
206
206
  message += f" It is linked to socket {socket2.name} from node {socket2.node.name}."
207
207
  message += " This link will be created by Blender but ignored when evaluated."
208
208
  message += f"Socket type: {socket.bl_idname}"
@@ -211,15 +211,14 @@ class TreeBuilder:
211
211
  return link
212
212
 
213
213
  def add(self, name: str) -> Node:
214
- self.just_added = self.tree.nodes.new(name) # type: ignore
215
- assert self.just_added is not None
216
- return self.just_added
214
+ return self.tree.nodes.new(name)
217
215
 
218
216
 
219
217
  class NodeBuilder:
220
218
  """Base class for all geometry node wrappers."""
221
219
 
222
220
  node: Any
221
+ _bl_idname: str
223
222
  _tree: "TreeBuilder"
224
223
  _link_target: str | None = None
225
224
  _from_socket: NodeSocket | None = None
@@ -241,7 +240,7 @@ class NodeBuilder:
241
240
  self._tree = tree
242
241
  self._link_target = None
243
242
  if self.__class__.name is not None:
244
- self.node = self._tree.add(self.__class__.name)
243
+ self.node = self._tree.add(self.__class__._bl_idname)
245
244
  else:
246
245
  raise ValueError(
247
246
  f"Class {self.__class__.__name__} must define a 'name' attribute"
@@ -273,7 +272,14 @@ class NodeBuilder:
273
272
  def _default_output_socket(self) -> NodeSocket:
274
273
  if self._default_output_id is not None:
275
274
  return self.node.outputs[self._output_idx(self._default_output_id)]
276
- return self.node.outputs[0]
275
+
276
+ counter = 0
277
+ socket = self.node.outputs[counter]
278
+ while not socket.is_icon_visible:
279
+ print(f"skipping inactive socket {socket.name}")
280
+ counter += 1
281
+ socket = self.node.outputs[counter]
282
+ return socket
277
283
 
278
284
  def _source_socket(self, node: LINKABLE | SocketLinker | NodeSocket) -> NodeSocket:
279
285
  assert node
@@ -805,7 +811,7 @@ class NodeBuilder:
805
811
  self, other: Any, operation: str, reverse: bool = False
806
812
  ) -> "VectorMath | Math":
807
813
  """Apply a math operation with appropriate Math/VectorMath node."""
808
- from .nodes.converter import VectorMath
814
+ from .nodes import VectorMath
809
815
 
810
816
  values = (
811
817
  (self._default_output_socket, other)