-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapi.py
More file actions
118 lines (86 loc) · 3.52 KB
/
api.py
File metadata and controls
118 lines (86 loc) · 3.52 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
"""Public API for the anchors system.
Provides a stable, documented interface for external Nuke templating systems to
create and look up anchor nodes without reaching into private internals.
Intended to be imported from .nuke/init.py or from pipeline scripts that run
inside a live Nuke session:
from api import create_anchor, find_anchor_by_name
Examples
--------
Create an anchor programmatically from a templating system:
>>> bg_read = nuke.toNode('Read_BG')
>>> anchor_node = create_anchor('BG_Plate', input_node=bg_read, color=0x8040FFFF)
Look up an existing anchor by its display name before creating a duplicate:
>>> existing = find_anchor_by_name('BG_Plate')
>>> if existing is None:
... anchor_node = create_anchor('BG_Plate')
"""
import sys
import anchor
def _assert_nuke_session():
"""Raise RuntimeError if nuke is not present in sys.modules.
This guards every public function so callers get a clear error message when
the API is used outside a running Nuke session (e.g., in an offline script).
"""
if 'nuke' not in sys.modules:
raise RuntimeError('anchors API requires a running Nuke session')
def create_anchor(name, input_node=None, color=None):
"""Create a named anchor node in the current Nuke script.
Thin wrapper over ``anchor.create_anchor_named`` that provides a stable
public surface for external callers.
Parameters
----------
name : str
Display name for the anchor. Special characters are sanitized
automatically; raises ``ValueError`` if the result is an empty string.
input_node : nuke.Node or None
Optional node to connect the anchor to and position it below.
color : int or None
Explicit tile color as a 0xRRGGBBAA integer. If ``None``, the color is
derived automatically from the anchor name.
Returns
-------
nuke.Node
The newly created anchor node.
Raises
------
ValueError
If *name* sanitizes to an empty string (e.g., ``'!!!'``).
RuntimeError
If nuke is not available in the current Python session.
Examples
--------
Create an anchor connected to an existing node with an explicit color:
>>> source_node = nuke.toNode('Read1')
>>> anchor_node = create_anchor('BG_Plate', input_node=source_node, color=0x8040FFFF)
Create a simple named anchor with automatic color:
>>> anchor_node = create_anchor('OutputPass')
"""
_assert_nuke_session()
return anchor.create_anchor_named(name, input_node, color)
def find_anchor_by_name(display_name):
"""Return the anchor node whose display name matches *display_name*, or None.
Thin wrapper over ``anchor.find_anchor_by_name`` that provides a stable
public surface for external callers.
Parameters
----------
display_name : str
The display name to search for. Comparison is case-sensitive.
Returns
-------
nuke.Node or None
The first anchor node whose display name equals *display_name*, or
``None`` if no such anchor exists in the current script.
Raises
------
RuntimeError
If nuke is not available in the current Python session.
Examples
--------
Look up an anchor before creating a duplicate:
>>> existing = find_anchor_by_name('BG_Plate')
>>> if existing is None:
... existing = create_anchor('BG_Plate')
"""
_assert_nuke_session()
return anchor.find_anchor_by_name(display_name)
__all__ = ['create_anchor', 'find_anchor_by_name']