]> git.walde.dev - blender_node_tools/commitdiff
Constant cleanup and docs
authorDustin Walde <redacted>
Wed, 27 Oct 2021 15:28:13 +0000 (08:28 -0700)
committerDustin Walde <redacted>
Wed, 27 Oct 2021 15:28:13 +0000 (08:28 -0700)
README.rst
blender_node_tools.py

index ea34ca67bf9488565c071b349859f72cf5dccba8..f34cbe1566e35168f36e77845cccd160a075681b 100644 (file)
@@ -1,7 +1,7 @@
 blender_node_tools
 ==================
 
-A python module of functions to aid in manipulating node connections
+A python function module to aid in manipulating node connections
 in Blender.
 
 The goal is to make it simpler when adding / removing links between
@@ -17,7 +17,7 @@ Now this can look like::
 
     link_nodes(node_tree, 'From Node', 'To Node:Input')
 
-Even more roundabout was the removal of links:
+Even more roundabout was the removal of links::
 
     for link in node_tree.links:
         if link.to_node == node_tree.nodes['Node'] \
@@ -38,7 +38,7 @@ Outputs::
 
 
 Something like a compositor mix node have two inputs of the same name
-"Image". These may be targeting with a subscript index notation::
+"Image". These may be targeting with array index notation::
 
     link_nodes(node_tree, "Image Texture", "Mix:Image[0]")
     link_nodes(node_tree, "Fade Texture",  "Mix:Image[1]")
index 529b8819cde5fba61c0d58fce526314c86601fe3..deb7beb6c717225bc95fa623f8195561b09896d0 100644 (file)
@@ -49,6 +49,11 @@ NodeGroupType = Union[
     ] # all have a #node_tree property and are Nodes
 NodeType = Union[str, Node, NodeSocket]
 
+INPUT_SYMBOL = '+'
+OUTPUT_SYMBOL = '-'
+SOCKET_DELIMETER = ':'
+PATH_DELIMETER = '/'
+
 def is_group(node: Node) -> bool:
     """
     Check if node is a *GroupNode of some sort
@@ -62,17 +67,19 @@ def build_path(*nodes: str,
     if input != False and output != False:
         raise ValueError("Path cannot be both input and output")
 
-    node_path = '/'.join(nodes)
+    node_path = PATH_DELIMETER.join(nodes)
+
+    def _format_socket_path(socket, symbol):
+        if isinstance(socket, str):
+            return '{}{}{}{}'.format(
+                symbol, node_path, SOCKET_DELIMETER, socket)
 
-    if type(input) == str:
-        return '+{}:{}'.format(node_path, input)
-    elif input:
-        return '+{}'.format(node_path)
+        return '{}{}'.format(symbol, node_path)
 
-    if type(output) == str:
-        return '-{}:{}'.format(node_path, output)
-    elif input:
-        return '-{}'.format(node_path)
+    if input != False:
+        return _format_socket_path(input, INPUT_SYMBOL)
+    elif output != False:
+        return _format_socket_path(output, OUTPUT_SYMBOL)
 
     return node_path
 
@@ -261,19 +268,20 @@ def _parse_path(node_path: str) -> Tuple[List[str], str, int, bool, bool]:
     socket_index = -1
     path_parts = None
 
-    if node_path[0] == '+':
+    if node_path[0] == INPUT_SYMBOL:
         output = False
         node_path = node_path[1:]
-    elif node_path[0] == '-':
+    elif node_path[0] == OUTPUT_SYMBOL:
         input = False
         node_path = node_path[1:]
 
-    parts = node_path.split(':')
+    parts = node_path.split(SOCKET_DELIMETER)
     if len(parts) > 1:
         socket = parts[-1]
-        path_parts = ':'.join(parts[:-1]).split('/')
+        path_parts = SOCKET_DELIMETER.join(parts[:-1])\
+            .split(PATH_DELIMETER)
     else:
-        path_parts = node_path.split('/')
+        path_parts = node_path.split(PATH_DELIMETER)
 
     if socket is not None:
         left_bracket = socket.find('[')