Skip to content

Instantly share code, notes, and snippets.

@chimanaco
Last active March 26, 2020 21:21
Show Gist options
  • Save chimanaco/6721e695e84de99bd520a5abb759c8cf to your computer and use it in GitHub Desktop.
Save chimanaco/6721e695e84de99bd520a5abb759c8cf to your computer and use it in GitHub Desktop.

Run with Variables

op('text_switch').run(0)

index = args[0]
op('switch1').par.index = index

Run with Delay

op('Save').run(delayFrames = 60 )

Run with Delay and args

op('Save').run(arg1, arg2, delayFrames = 60 )
See https://docs.derivative.ca/Td_Module

Use global shortcut inside expression

# There is a component that has 'MAT' as its global shortcut name. 
pre = 'op.' + op('parameter1')['Matpath', 1] + '.'
o = op('null1')
o.par.top.expr = pre + 'op("' + o.name + '")'

# result: op.MAT.op('null1')

Viewer

op('container1').openViewer()
op('container1').closeViewer()

if

a = 200
b = 33
if b > a:
  print("b is greater than a")
elif a == b:
  print("a and b are equal")
else:
  print("a is greater than b")
# In a parameter on an operator.
1280 if parent() == '/' else parent().par.w

for loop

opValues = op('select1') // CHOP
opText = op('text1')	
len = opTable.numChans

for i in range(len):
  opText.run(opValues[i].name, opValues[i])

Change Mode

op('constant1).par.Value0.mode = ParMode.CONSTANT
op('constant1).par.Value0.mode = ParMode.EXPRESSION
op('constant1).par.Value0.mode = ParMode.EXPORT

Connect and disconnect

opTable = op('TargetComp')
compPath = "Parameters/"
len = opTable.numRows

for i in range(len):
    op(compPath + opTable[i, 0]).outputConnectors[0].disconnect()
    op(compPath + opTable[i, 0]).outputConnectors[0].connect(op(compPath + 'merge1'))

Get the same number of samples from another CHOP

# e.g. Noise -> Channel -> End
op('sopto1').numSamples/me.time.rate

Math

# x
math.cos(absTime.seconds / 10) * 10
# y
math.sin(absTime.seconds / 10) * 10

Limiting floats to two decimal points

"%.2f" % op('select1')['depth3']

Change flag

# bypass
op('name').bypass = True
op('name').bypass = False

# cooking
op('name').allowCooking = True
op('name').allowCooking = False

Regular Expression

# 1_hello -> hello
re.sub(r'[0-9]{1,2}_', "", me.name)

# Remove strings
targetName = str(name).replace('.tox','')

Rename

# From
*
# To
op('label').par.Widgetlabel + '*'

Shortcut

Add a Null operator alt + n

Destroy

# Destroy op
c = ownerComp.children
for o in c:
if targetName in o.name:
  o.destroy()

Open UI

# Export Movie Dialog
ui.openExportMovie("/project1/null1")

More

https://docs.derivative.ca/UI_Class

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment