raganmd
5/7/2019 - 1:11 AM

load_preset

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)