1
+ import bpy
2
+ import inspect
3
+ import typing
4
+
5
+ def repeat_zone (block : typing .Callable ):
6
+ """
7
+ Create a repeat input/output block.
8
+
9
+ > Only available in Blender 4.0+.
10
+ """
11
+ def wrapped (* args , ** kwargs ):
12
+ from geometry_script .api .node_mapper import OutputsList , set_or_create_link
13
+ from geometry_script .api .state import State
14
+ from geometry_script .api .types import Type , socket_class_to_data_type
15
+
16
+ signature = inspect .signature (block )
17
+
18
+ # setup zone
19
+ repeat_in = State .current_node_tree .nodes .new (bpy .types .GeometryNodeRepeatInput .__name__ )
20
+ repeat_out = State .current_node_tree .nodes .new (bpy .types .GeometryNodeRepeatOutput .__name__ )
21
+ repeat_in .pair_with_output (repeat_out )
22
+
23
+ # clear state items
24
+ for item in repeat_out .repeat_items :
25
+ repeat_out .repeat_items .remove (item )
26
+
27
+ # link the iteration count
28
+ set_or_create_link (args [0 ], repeat_in .inputs [0 ])
29
+
30
+ # create state items from block signature
31
+ repeat_items = {}
32
+ for param in signature .parameters .values ():
33
+ repeat_items [param .name ] = (param .annotation , param .default , None , None )
34
+ for i , arg in enumerate (repeat_items .items ()):
35
+ repeat_out .repeat_items .new (socket_class_to_data_type (arg [1 ][0 ].socket_type ), arg [0 ].replace ('_' , ' ' ).title ())
36
+ # skip the first index, which is reserved for the iteration count
37
+ i = i + 1
38
+ set_or_create_link (kwargs [arg [0 ]] if arg [0 ] in kwargs else args [i ], repeat_in .inputs [i ])
39
+
40
+ step = block (* [Type (o ) for o in repeat_in .outputs [:- 1 ]])
41
+
42
+ if isinstance (step , Type ):
43
+ step = (step ,)
44
+ for i , result in enumerate (step ):
45
+ set_or_create_link (result , repeat_out .inputs [i ])
46
+
47
+ if len (repeat_out .outputs [:- 1 ]) == 1 :
48
+ return Type (repeat_out .outputs [0 ])
49
+ else :
50
+ return OutputsList ({o .name .lower ().replace (' ' , '_' ): Type (o ) for o in repeat_out .outputs [:- 1 ]})
51
+ return wrapped
0 commit comments