Add enum generation
This commit is contained in:
parent
f2d6280024
commit
828fb8b6da
9 changed files with 226 additions and 40 deletions
|
|
@ -20,7 +20,47 @@ The general process is:
|
|||
|
||||
> Properties and inputs are different types of argument. A property is a value that cannot be connected to a socket. These are typically enums (displayed in the UI as a dropdown), with specific string values expected. Check the documentation for a node to see what the possible values are for a property.
|
||||
|
||||
Let's take a look at two nodes as an example.
|
||||
## Enum Properties
|
||||
|
||||
Many nodes have enum properties. For example, the math node lets you choose which operation to perform. You can pass a string to specify the enum case to use. But a safer way to set these values is with the autogenerated enum types. The enums are namespaced to the name of the node in PascalCase:
|
||||
|
||||
```python
|
||||
# Access it by Node.Enum Name.Case
|
||||
math(operation=Math.Operation.Add)
|
||||
math(operation=Math.Operation.Subtract)
|
||||
math(operation='MULTIPLY') # Or manually pass a string
|
||||
```
|
||||
|
||||
Internally, this type is generated as:
|
||||
|
||||
```python
|
||||
import enum
|
||||
class Math:
|
||||
class Operation(enum.Enum):
|
||||
Add = 'ADD'
|
||||
Subtract = 'SUBTRACT'
|
||||
Multiply = 'MULTIPLY'
|
||||
...
|
||||
...
|
||||
```
|
||||
|
||||
The cases will appear in code completion if you setup an [external editor](../../setup/external-editing.md).
|
||||
|
||||
## Duplicate Names
|
||||
|
||||
Some nodes use the same input name multiple times. For example, the *Math* node has three inputs named `value`. To specify each value, pass a tuple for the input:
|
||||
|
||||
```python
|
||||
math(operation=Math.Operation.Wrap, value=(0.5, 1, 0)) # Pass all 3
|
||||
math(operation=Math.Operation.Wrap, value=(0.5, 1)) # Only pass 2/3
|
||||
math(operation=Math.Operation.Wrap, value=0.5) # Only pass 1/3
|
||||
```
|
||||
|
||||

|
||||
|
||||
## Examples
|
||||
|
||||
Here are two examples to show how a node maps to a function.
|
||||
|
||||
### Cube
|
||||
|
||||
|
|
@ -72,8 +112,8 @@ size.cube(...)
|
|||
1. Name `Capture Attribute` -> `capture_attribute`
|
||||
2. Keyword Arguments
|
||||
* Properties
|
||||
* `data_type: Literal['FLOAT', 'INT', 'FLOAT_VECTOR', 'FLOAT_COLOR', 'BYTE_COLOR', 'STRING', 'BOOLEAN', 'FLOAT2', 'INT8']`
|
||||
* `domain: Literal['POINT', 'EDGE', 'FACE', 'CORNER', 'CURVE', 'INSTANCE']`
|
||||
* `data_type: CaptureAttribute.DataType`
|
||||
* `domain: CaptureAttribute.Domain`
|
||||
* Inputs
|
||||
* `geometry: Geometry`
|
||||
* `value: Vector | Float | Color | Bool | Int`
|
||||
|
|
@ -82,7 +122,7 @@ size.cube(...)
|
|||
The node can now be used as a function:
|
||||
|
||||
```python
|
||||
result = capture_attribute(data_type='BOOLEAN', geometry=cube_geo) # Specify a property and an input
|
||||
result = capture_attribute(data_type=CaptureAttribute.DataType.Boolean, geometry=cube_geo) # Specify a property and an input
|
||||
result.geometry # Access the geometry
|
||||
result.attribute # Access the attribute
|
||||
```
|
||||
|
|
@ -92,8 +132,8 @@ The generated documentation will show the signature, result type, and [chain syn
|
|||
#### Signature
|
||||
```python
|
||||
capture_attribute(
|
||||
data_type: Literal['FLOAT', 'INT', 'FLOAT_VECTOR', 'FLOAT_COLOR', 'BYTE_COLOR', 'STRING', 'BOOLEAN', 'FLOAT2', 'INT8'],
|
||||
domain: Literal['POINT', 'EDGE', 'FACE', 'CORNER', 'CURVE', 'INSTANCE'],
|
||||
data_type: CaptureAttribute.DataType,
|
||||
domain: CaptureAttribute.Domain,
|
||||
geometry: Geometry,
|
||||
value: Vector | Float | Color | Bool | Int
|
||||
)
|
||||
|
|
|
|||
Reference in a new issue