load_preset
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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