Skip to content

Instantly share code, notes, and snippets.

@raganmd
Last active May 7, 2019 00:01

Revisions

  1. raganmd revised this gist May 7, 2019. 1 changed file with 1 addition and 2 deletions.
    3 changes: 1 addition & 2 deletions dict_to_storage.py
    Original file line number Diff line number Diff line change
    @@ -20,8 +20,7 @@ def dict_to_storage(target_op, storage_dict_key, preset_name, dict_to_store):
    Returns
    ---------------
    par_dict (dict)
    > a dictionary containing a preset name and dictionary of parameters.
    None
    '''
    # grab the dictionary from storage
    all_presets = target_op.fetch(storage_dict_key)
  2. raganmd revised this gist May 6, 2019. 1 changed file with 28 additions and 0 deletions.
    28 changes: 28 additions & 0 deletions dict_to_storage.py
    Original file line number Diff line number Diff line change
    @@ -1,7 +1,35 @@
    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
    ---------------
    par_dict (dict)
    > a dictionary containing a preset name and dictionary of parameters.
    '''
    # 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
  3. raganmd created this gist May 6, 2019.
    18 changes: 18 additions & 0 deletions dict_to_storage.py
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,18 @@
    def dict_to_storage(target_op, storage_dict_key, preset_name, dict_to_store):
    all_presets = target_op.fetch(storage_dict_key)
    all_presets[preset_name] = dict_to_store

    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)