Skip to content

Commit 7001a17

Browse files
committed
Add scripted_expression helper function
1 parent 1cdd975 commit 7001a17

File tree

6 files changed

+22
-0
lines changed

6 files changed

+22
-0
lines changed

api/node_mapper.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ def build(_primary_arg=None, **kwargs):
3030
value = value.value
3131
setattr(node, prop.identifier, value)
3232
for node_input in (node.inputs[1:] if _primary_arg is not None else node.inputs):
33+
if not node_input.enabled:
34+
continue
3335
argname = node_input.name.lower().replace(' ', '_')
3436
all_with_name = []
3537
for node_input2 in (node.inputs[1:] if _primary_arg is not None else node.inputs):

api/static/expression.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
def scripted_expression(scripted_expression: str) -> 'Type':
2+
from geometry_script import Type, State
3+
value_node = State.current_node_tree.nodes.new('ShaderNodeValue')
4+
fcurve = value_node.outputs[0].driver_add("default_value")
5+
fcurve.driver.expression = scripted_expression
6+
return Type(value_node.outputs[0])

api/tree.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
from .types import *
99
from .node_mapper import *
1010
from .static.input_group import *
11+
from .static.expression import *
1112

1213
def _as_iterable(x):
1314
try:

api/types.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ def __init__(self, socket: bpy.types.NodeSocket = None, value = None):
3838
tuple: ('FunctionNodeInputVector', 'vector'),
3939
float: ('ShaderNodeValue', None),
4040
}
41+
if type(value) == int:
42+
print("Making an integer node?")
4143
if not type(value) in input_nodes:
4244
raise Exception(f"'{value}' cannot be expressed as a node.")
4345
input_node_info = input_nodes[type(value)]

book/src/SUMMARY.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
- [Input Groups](./api/advanced-scripting/input-groups.md)
2222
- [Attributes](./api/advanced-scripting/attributes.md)
2323
- [Boolean Math](./api/advanced-scripting/boolean-math.md)
24+
- [Drivers](./api/advanced-scripting/drivers.md)
2425

2526
# Tutorials
2627

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# Drivers
2+
3+
Drivers can be used with geometry nodes. To create a scripted expression driver, use the `scripted_expression` convenience function.
4+
5+
This can be used to get information like the current frame number in a Geometry Script.
6+
7+
```python
8+
frame_number = scripted_expression("frame")
9+
frame_number_doubled = scripted_expression("frame * 2")
10+
```

0 commit comments

Comments
 (0)