Skip to content

Commit 5bf180f

Browse files
externalized most scripts
1 parent b7c2154 commit 5bf180f

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

62 files changed

+2388
-0
lines changed
-96 Bytes
Binary file not shown.
0 Bytes
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.

scripts/AltSelect/AltSelectExt.py

+77
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
class AltSelectExt:
2+
"""
3+
AltSelectExt description
4+
"""
5+
def __init__(self, ownerComp):
6+
# The component to which this extension is attached
7+
self.ownerComp = ownerComp
8+
self.lastSelectedPos = (0, 0)
9+
self.family_to_selectpar = {
10+
'SOP':'sop',
11+
'TOP':'top',
12+
'CHOP':'chops',
13+
'DAT':'dat',
14+
'COMP':'selectpanel'
15+
}
16+
self.selectColor = (0.71, 0.53, 0.16)
17+
self.lastSelectedPos = None
18+
19+
20+
def OnSelectOP(self, _op):
21+
if _op:
22+
self.lastSelectedPos = {'op_pos': (_op.nodeX, _op.nodeY), 'docked_pos': {_dock: (_dock.nodeX, _dock.nodeY) for _dock in _op.docked}}
23+
24+
25+
@property
26+
def hotkey(self) -> bool:
27+
return bool(self.ownerComp.op('null_hk')[0].eval())
28+
29+
30+
def OnUpdate(self, _op: OP):
31+
if not self.hotkey:
32+
return
33+
34+
new_pos = (_op.nodeX, _op.nodeY)
35+
if self.lastSelectedPos and (new_pos != self.lastSelectedPos):
36+
self.onPosChange(_op, new_pos, self.lastSelectedPos)
37+
38+
39+
def onPosChange(self, _op, new_pos, last_pos):
40+
if _op.family not in self.family_to_selectpar.keys():
41+
self.lastSelectedPos = None
42+
return
43+
# selectCOMP only works with Panel types
44+
if isinstance(_op, COMP) and not _op.isPanel:
45+
self.lastSelectedPos = None
46+
return
47+
48+
ui.undo.startBlock('Selecting OP') #---------
49+
50+
sel_par = self.family_to_selectpar[_op.family]
51+
sel_fam = _op.family
52+
53+
new_select = _op.parent().create(f'select{sel_fam}',
54+
f"select_{_op.name.split('_')[-1]}")
55+
new_select.nodeX = new_pos[0]
56+
new_select.nodeY = new_pos[1]
57+
new_select.par[sel_par] = _op
58+
new_select.viewer = True
59+
new_select.color = self.selectColor
60+
_op.selected = False
61+
new_select.selected = True
62+
new_select.current = True
63+
64+
# I usually have this enabled anyway
65+
if _op.isPanel:
66+
new_select.par.matchsize = True
67+
68+
ui.undo.endBlock() # -------------------------
69+
70+
# restore pos
71+
_op.nodeX = last_pos['op_pos'][0]
72+
_op.nodeY = last_pos['op_pos'][1]
73+
74+
for _dock in _op.docked:
75+
if _dock in last_pos['docked_pos'].keys():
76+
_dock.nodeX = last_pos['docked_pos'][_dock][0]
77+
_dock.nodeY = last_pos['docked_pos'][_dock][1]

scripts/AutoCombine/AutoCombineExt.py

+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
"""
2+
Extension classes enhance TouchDesigner components with python. An
3+
extension is accessed via ext.ExtensionClassName from any operator
4+
within the extended component. If the extension is promoted via its
5+
Promote Extension parameter, all its attributes with capitalized names
6+
can be accessed externally, e.g. op('yourComp').PromotedFunction().
7+
8+
Help: search "Extensions" in wiki
9+
"""
10+
11+
from TDStoreTools import StorageManager
12+
import TDFunctions as TDF
13+
14+
class AutoCombineExt:
15+
"""
16+
AutoCombineExt description
17+
"""
18+
def __init__(self, ownerComp):
19+
# The component to which this extension is attached
20+
self.ownerComp = ownerComp
21+
22+
def SetCombine(self, _op):
23+
if not _op.inputs:
24+
return
25+
if self.ownerComp.op('null_hk')['activate'].eval():
26+
if _op.pars('combineinput'):
27+
try:
28+
_op.par.combineinput.val = parent.AutoCombine.par.Combineinput.eval()
29+
_op.par.operand.val = parent.AutoCombine.par.Operand.eval()
30+
except:
31+
pass
32+
if _op.pars('rgb'):
33+
try:
34+
_op.par.rgb.val = parent.AutoCombine.par.Rgb.eval()
35+
except:
36+
pass
37+
if _op.pars('format'):
38+
_op.par.format.val = parent.AutoCombine.par.Format.eval()
39+
pass

scripts/AutoRes/AutoResExt.py

+50
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
"""
2+
Extension classes enhance TouchDesigner components with python. An
3+
extension is accessed via ext.ExtensionClassName from any operator
4+
within the extended component. If the extension is promoted via its
5+
Promote Extension parameter, all its attributes with capitalized names
6+
can be accessed externally, e.g. op('yourComp').PromotedFunction().
7+
8+
Help: search "Extensions" in wiki
9+
"""
10+
11+
from TDStoreTools import StorageManager
12+
import TDFunctions as TDF
13+
14+
class AutoResExt:
15+
"""
16+
AutoResExt description
17+
"""
18+
def __init__(self, ownerComp):
19+
# The component to which this extension is attached
20+
self.ownerComp = ownerComp
21+
22+
def SetRes(self, _op):
23+
if self.ownerComp.op('null_hk')['activate'].eval() and _op.pars('outputresolution'):
24+
if not _op.inputs:
25+
if _op.par.outputresolution.enable and not _op.isFilter:
26+
27+
parentPanel = False
28+
i = 1
29+
try:
30+
while not parentPanel:
31+
parentPanel = _op.parent(i).isPanel
32+
i += 1
33+
except:
34+
pass
35+
if parentPanel:
36+
_op.par.outputresolution.val = 10
37+
else:
38+
_op.par.outputresolution.val = 9
39+
_op.par.resolutionw.expr = "tdu.tryExcept(lambda: parent.Project.width, op.AUTO_RES.par.Resolutionw)"
40+
_op.par.resolutionh.expr = "tdu.tryExcept(lambda: parent.Project.height, op.AUTO_RES.par.Resolutionh)"
41+
42+
if _op.pars('rgb'):
43+
try:
44+
_op.par.rgb.val = parent.AutoRes.par.Rgb.eval()
45+
except:
46+
pass
47+
if _op.pars('format'):
48+
_op.par.format.val = parent.AutoRes.par.Format.eval()
49+
50+
pass

scripts/ClearPars/ClearParsExt.py

+44
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
2+
class ClearParsExt:
3+
"""
4+
ClearParsExt description
5+
"""
6+
def __init__(self, ownerComp):
7+
# The component to which this extension is attached
8+
self.ownerComp = ownerComp
9+
self.Op = None
10+
11+
def ClearPars(self):
12+
13+
_ops = [self.Op]
14+
15+
if self.ownerComp.par.Recursive.eval():
16+
if _op := _ops[0]:
17+
if _op.isCOMP:
18+
_ops.extend(_op.findChildren(depth=1, includeUtility=False, key=lambda _o: _o.opType != 'annotateCOMP' and 'annotate' not in _o.name))
19+
20+
ui.undo.startBlock('Clear Par Errors')
21+
for _op in _ops:
22+
if _op is None:
23+
continue
24+
for _par in _op.pars():
25+
if _par.name == 'autoexportroot' or 'expr' in _par.name:
26+
continue
27+
if _par.valid:
28+
if _par.mode == ParMode.BIND:
29+
if _par.bindMaster == None:
30+
_par.bindExpr = None
31+
_par.expr = None
32+
_par.mode = ParMode.CONSTANT
33+
pass
34+
if _par.mode == ParMode.EXPRESSION:
35+
try:
36+
_par.eval()
37+
except:
38+
_par.expr = None
39+
_par.bindExpr = None
40+
_par.mode = ParMode.CONSTANT
41+
42+
if _op.isCOMP and _op.opType != annotateCOMP:
43+
_op.clearScriptErrors(recurse=True)
44+
ui.undo.endBlock()

0 commit comments

Comments
 (0)