Last active
May 4, 2019 03:12
-
-
Save raganmd/d60143c8d543e69a62d289fb66834c8c to your computer and use it in GitHub Desktop.
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 page_to_dict(target_op, target_page, p_name, ignore_list): | |
''' | |
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. | |
target_page (str): | |
> the string name of the page whose parameters you would like to | |
> convert into a python dictionary. | |
p_name (str): | |
> a name for the preset / cue. | |
ignore_list (list): | |
> a list of parameters you do not want to include. | |
Returns | |
--------------- | |
par_dict (dict) | |
> a dictionary containing a preset name and dictionary of parameters. | |
''' | |
# create empty par_dict with input name as the preset_name value | |
par_dict = { | |
"preset_name" : p_name, | |
"preset_vals" : {} | |
} | |
# loop through each parameter in the target_op and capture its name and | |
# value only if its custom page matches the input string for target_page, | |
# and the pars are not on the ignore_list | |
for each_par in target_op.pars(): | |
if each_par.isCustom and each_par.page == target_page and each_par.name not in ignore_list: | |
par_dict["preset_vals"][each_par.name] = each_par.val | |
return par_dict | |
# example use | |
target_op = op('base_preset_builder') | |
page = "Remnants Presets" | |
p_name = target_op.par.Presetname.val | |
ignore_list = ["Presetname", "Recordcue"] | |
presets = page_to_dict(target_op, page, p_name, ignore_list) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment