SideFX Houdini customization package
git clone https://git.lucas.co/hou-control.git
scripts/OnCreated.py (1.4K)
1 import hou
2 from hc import HCSettings
3
4 node = kwargs['node']
5 settings = HCSettings()
6 node_graph = settings.nodeGraph()
7
8 node.setUserData("nodeshape", settings.nodeShape())
9
10 # Record the color we apply, not a bare "1" flag: HCSession.updateNodeColors()
11 # only recolors a node whose current color still matches this record, which is
12 # what lets a hand-picked color survive the next hip load.
13 #
14 # With coloring off, leave no colour and no tag at all -- a tag written now
15 # would make the node managed again the moment the setting is turned back on,
16 # which is not what "off" should leave behind.
17 if settings.nodeColoringEnabled():
18 node.setUserData("hc_custom_color", settings.nodeColorHex())
19 node.setColor(settings.nodeColor())
20
21 # Snap to the same grid HCNetworkEditor uses. This used to hardcode a 1.0 grid
22 # with a 0.5/0.85 offset, so any non-default grid_*_step left every new node
23 # off-grid until it was nudged.
24 step_x = max(node_graph.get("grid_x_step", 2.0), 0.25)
25 step_y = max(node_graph.get("grid_y_step", 1.0), 0.25)
26 offset_x = node_graph.get("node_center_offset_x", 0.5)
27 offset_y = node_graph.get("node_center_offset_y", 0.15)
28
29 pos = node.position()
30 # position() is the bottom-left corner; the grid applies to the node's center.
31 node.setPosition(hou.Vector2(
32 round((pos[0] + offset_x) / step_x) * step_x - offset_x,
33 round((pos[1] + offset_y) / step_y) * step_y - offset_y,
34 ))