Skip to content

Instantly share code, notes, and snippets.

@raganmd
Last active May 7, 2019 01:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save raganmd/89eafe6be52e11471e5c15ad4dace911 to your computer and use it in GitHub Desktop.
Save raganmd/89eafe6be52e11471e5c15ad4dace911 to your computer and use it in GitHub Desktop.
load_preset
def load_preset(preset_name, storage_op, target_op):
'''
A Helper function that writes JSON file to disk
Args
---------------
preset_name (str):
> the string name of the preset we want to load
storage_op (TouchDesigner operator):
> the target operator storing the presets.
target_op (TouchDesigner operator):
> the target operator whose values we want to set.
Returns
---------------
None
'''
# safety to ensure we have a preset to use
try:
preset_vals = storage_op.fetch("presets")[preset_name]
except:
print("This preset does not exist")
# loop through all pars and set them based on the vals in storage
for each_par, each_val in preset_vals.items():
target_op.pars(each_par)[0].val = each_val
target_op.par.Presetname = preset_name
# example use
target_op = op('base_target')
storage_op = op('base_example')
preset_name = 'look002'
load_preset(preset_name, storage_op, target_op)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment