|
from -- https://github.com/nortikin/sverchok/issues/1653
|
|
### Default Presets
|
|
|
|
|
|
the following document is now deprecated (without replacement). per https://github.com/nortikin/sverchok/pull/3483
|
|
When we (as coders) submit a node, we decide on sane defaults. Sometimes those defaults are not optimal for you (the user). If you find yourself always tweaking the parameters of a node before using it, then you might want to define custom node defaults. This is done by using Presets mechanism.
|
|
|
|
|
|
----
|
|
How it works:
|
|
|
|
|
|
### Node Defaults
|
|
* You configure the node as you wish
|
|
|
|
* You go to it's Presets menu (in the N panel, or in the node's context menu, or you can press Shift-P), and select "Save current settings as node preset"
|
|
|
|
* Enter **Default** (case sensitive) as the name of the preset.
|
|
|
|
|
|
When we (as coders) submit a node, we decide on sane defaults. Sometimes those defaults are not optimal for you (the user). If you find yourself always tweaking the parameters of a node before using it, then you might want to define custom node defaults. These are not the same as presets.
|
|
Now, when you create node of the same type by any usual way (from Shift-A menu, from T panel, from Search menu), this Default preset will be automatically applied. This preset will not be applied when the node is created as part of another (multi-node) preset being imported.
|
|
|
|
|
|
we can configure two things:
|
|
|
|
- (**node props**) any property on the node, including props that are not available from the UI
|
|
|
|
- (**node function**) we can write a function, (explained below) and call this function on a specific node whenever it is created.
|
|
|
|
|
|
|
|
We can now configure node defaults from a _.json_ file located in `..datafiles/sverchok/node_defaults/`. We can tell sverchok where to find this file by including the location of datafiles/sverchok in the user preferences of sverchok. It will look something like this:
|
|
|
|
|
|
|
|

|
|
|
|
|
|
|
|
##### datafiles/sverchok/node_defaults/node_defaults.json
|
|
|
|
```json
|
|
|
|
{
|
|
|
|
|
|
|
|
"SvGenNumberRange": {
|
|
|
|
"props": [
|
|
|
|
["stop_float", 1.0],
|
|
|
|
["count_", 20],
|
|
|
|
["range_mode", "RANGE_COUNT"]
|
|
|
|
]
|
|
|
|
},
|
|
|
|
|
|
|
|
"SvVDExperimental": {
|
|
|
|
"props": [],
|
|
|
|
"function": "view3d.init_vdmk3"
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
```
|
|
|
|
All we have to do is create `(key, value pair)` for each node.
|
|
|
|
|
|
|
|
- key: ( the node's `bl_idname`)
|
|
|
|
- value: Currently the `value` accepts two directives (but can be extended later)
|
|
|
|
|
|
|
|
1. `props` ( _push props in sequence with a list of prop_name, prop_value pairs._ )
|
|
|
|
2. `function` ( _push a function:_ in the example below the function is referenced as `view3d.init_vdmk3`. read that as `filename.function` and filename shall be located in `datafiles/sverchok/node_defaults/` )
|
|
|
|
|
|
|
|

|
|
|
|
|
|
|
|
##### datafiles/sverchok/node_defaults/view3d.py
|
|
|
|
```python
|
|
|
|
import random
|
|
|
|
import colorsys
|
|
|
|
|
|
|
|
import bpy
|
|
|
|
|
|
|
|
|
|
|
|
def init_vdmk3(node):
|
|
|
|
|
|
|
|
def fold_color(color, shift):
|
|
|
|
h, s, v = colorsys.rgb_to_hsv(*color)
|
|
|
|
return list(colorsys.hsv_to_rgb(shift, s, v))
|
|
|
|
|
|
|
|
A = [0.938000, 0.948000, 0.900000, 1.000000]
|
|
|
|
B = [0.500000, 0.752000, 0.899000, 1.000000]
|
|
|
|
C = [0.030100, 0.488000, 0.899000, 1.000000]
|
|
|
|
|
|
|
|
shift = random.random()
|
|
|
|
node.vertex_color = fold_color(A[:3], shift) + [1.0]
|
|
|
|
node.edge_color = fold_color(B[:3], shift) + [1.0]
|
|
|
|
node.face_color = fold_color(C[:3], shift) + [1.0]
|
|
|
|
|
|
|
|
node.line_width = 1.0
|
|
|
|
node.point_size = 2.0
|
|
|
|
```
|
|
|
|
|
|
|
|
this default function will generate nicely shifted colour palettes for the viewer node, whenever you add a new viewnode with that bl_idname, like this
|
|
|
|
|
|
|
|

|
|
|
|
|
|
|
|
------------------
|
|
|
|
|
|
|
|
Each time you add a node, the `node_default_dict` is checked if the `bl_idname` has an entry.
|
|
|
|
|
|
|
|
- this has no effect on nodes that you duplicate, they clone their properties according to `self.copy()`
|
|
|
|
- this doesn't offer a visual way to set the preferences yet, that would be the next step.
|
|
|
|
|
|
|
|
|
|
These Default presets are available in the Presets panel under T panel; you can rename them, or remove as well as others. |
|
|
|
\ No newline at end of file |