Skip to content

Instantly share code, notes, and snippets.

@raganmd
Last active May 7, 2019 00:01
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/ee258ae5ebdfdb07c23e3a139824f061 to your computer and use it in GitHub Desktop.
Save raganmd/ee258ae5ebdfdb07c23e3a139824f061 to your computer and use it in GitHub Desktop.
def dict_to_storage(target_op, storage_dict_key, preset_name, dict_to_store):
'''
A reusable method for capturing parameters on a single page of a COMP
Args
---------------
target_op (TouchDesigner COMP):
> a ToughDesigner COMP that has custom parameters you would like to convert
> into a python dictionary.
storage_dict_key (str):
> the string name of the storage dictionary you'd like to add
> your preset / cue to.
preset_name (str):
> a name for the preset / cue.
dict_to_store (dict):
> a python dictionary to put into storage.
Returns
---------------
None
'''
# grab the dictionary from storage
all_presets = target_op.fetch(storage_dict_key)
# create a new entry
all_presets[preset_name] = dict_to_store
# put dictionary back into storage
target_op.store(storage_dict_key, all_presets)
# example use
target_op = op('base_example')
storage_dict_key = 'presets'
preset_name = 'look001'
dict_to_store = {"preset_values": {
'Blacklevel' : 0.0,
'Contrast' : 1.0,
'Opacity' : 1.0
}
}
dict_to_storage(target_op, storage_dict_key, preset_name, dict_to_store)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment