Use Python extension on parent to provide interface to child's custom parameters

Hello there,

I feel like I’m finally understanding the reuse potentials of .tox components and extension scripts so I have a quick question. If I design a component with custom parameters for distorting an input image and save it as a tox file how can I in a new network place this as a child of another base and programmatically surface the original image distorting custom parameters?

I was happy to read about this on Expose child TOP parameters on the parent base component that there is a suggested manual process with the customize component ui, but I’m looking for something different.

I’m picturing the following steps and if other people think something different should apply please chime in!

  • recurse in the parent extension through it’s contents looking for comps who’s pages pass the isCustom page check
  • make a new page on the parent
  • iterate over the child’s custom page params, and for each appending the correct param type to the parent’s page. then making sure to set the child’s custom param’s .expr to ext.ParentExtension.par.Paramname so that the modifications from the parent parameter go down to child

Is there anything more suggested that this?

also look at the TDJSON module for several handy methods to read all parameters from a page/component into a Python object, and then recreate all parameters on another COMP from that object.

I went with this code which recreates the float custom params from custom children, but the tdjson might be the more appropriate approach

def populate_child_params(cls):
    # check if there's a mapped child params element on the class or else error
    try:
        print(cls.mappedChildParams)
    except:
        print("COULDN'T work with child params, please add a mappedChildParam {} member to the extension class")
        return
    extroot = cls.ownerComp
    ops = cls.ownerComp.children

    while len(ops) >0:
        current = ops.pop()
        current_children = current.children
        ops.extend(current_children)
        ## check for custom pages on the operator
        if len(current.customPages)>0:
            child_custom_page= current.customPages[0]
            print(child_custom_page)
            # profile the params on the custom page for relevant information
            custom_pars= child_custom_page.pars
            print(child_custom_page.name,"is the name")
            # check if this page is already on the root
            should_continue=False
            for rt_page in extroot.pages:
                if rt_page.name == child_custom_page.name:
                    print("already have this param page")
                    should_continue=True
                    break
            if should_continue:
                continue
            rt_newpage= extroot.appendCustomPage(child_custom_page.name)
            for par in custom_pars:
                print("\tpar name is",par.name,"value is",par)
                if par.isFloat:
                    rt_par = rt_newpage.appendFloat(par.name)
                    rt_par.default = par.default
                    rt_par.normMin = par.normMin
                    rt_par.normMax = par.normMax
                    cls.mappedChildParams[par.name] = rt_par
                    # make a reference on the child to the parent's value
                    par.expr = f'op("{extroot.path}").par.{rt_par.name}'

I tried to do something where I stored the parameters under a dictionary that I could use in expressions later

ext.ExtensionName.mappedChildParams[name] but for some reason I wouldn’t see any updates happen upon interacting with the parent custom parameter sliders. This wasn’t a behavior I was able to recreate when I tried it elsewhere though, so who knows what caused the issue.