Copy a parameter from a child to its parent

Hi I want to copy the parameters from a base component child to its parent, it works but the RGBA RGB UV XY and all those parameters with multiple values are getting exponencial copies.

If someone can help me would be great it seams I am stuck here doing loops

and here is my code sorry I dont get how to insert it correctly:

def onOffToOn(channel, sampleIndex, val, prev):
    print("onOffToOn function called")
    parent_comp = parent()
    newPage = parent_comp.appendCustomPage("Custom")    
    
    for child_comp in parent_comp.findChildren(type=baseCOMP):
        print(f"Processing child: {child_comp.path}")
        
        for par in child_comp.customPars:
            try:
                newPar = getattr(newPage, f'append{par.style}', newPage.appendFloat)(par.name, label=par.label)
                newPar.bindExpr = f'op("{child_comp.path}").par.{par.name}'
                # Copy attributes for the new parameter tuplet
                if isinstance(newPar, tuple):
                    for p in newPar:
                        p.normMin = par.normMin
                        p.normMax = par.normMax
                        p.default = par.default
                        p.min = par.min
                        p.clampMin = par.clampMin
                        p.max = par.max
                        p.clampMax = par.clampMax
                else:
                    newPar.normMin = par.normMin
                    newPar.normMax = par.normMax
                    newPar.default = par.default
                    newPar.min = par.min
                    newPar.clampMin = par.clampMin
                    newPar.max = par.max
                    newPar.clampMax = par.clampMax
                    
            except Exception as e:
                print(f"Error processing {par.name}: {e}")
    return

Hi @Abas.fly,

we have the concept of parGroup and par. An RGBA parGroup is a collection of 4 parameters.
So in your case instead of looping through parameters, loop through parGroups and create them accordingly.

More information on parGroups can be found here:

Hope this helps
cheers
Markus

1 Like

That was exactly what I was missing, thanks very much!!!
I will leave the code here for the future in case someone has the same questions.
This is a Chop execute conected to a constant inside the base next to the child.

def onOffToOn(channel, sampleIndex, val, prev):
    parent_comp = parent()
    newPage = parent_comp.appendCustomPage("Custom")

    for child_comp in parent_comp.findChildren(type=baseCOMP):
        # Process parameter groups for multi-value parameters
        for parGroup in child_comp.customParGroups:
            try:
                if parGroup.style in ['RGBA', 'XYZ', 'UV', 'XY', 'RGB']:
                    # Only process group types
                    newParGroup = getattr(newPage, f'append{parGroup.style}', newPage.appendFloat)(parGroup.name, label=parGroup.label)
                    for i, par in enumerate(parGroup):
                        newParGroup[i].bindExpr = f'op("{child_comp.path}").par.{par.name}'
                        newParGroup[i].default = par.default
                        newParGroup[i].min = par.min
                        newParGroup[i].max = par.max
                        newParGroup[i].clampMin = par.clampMin
                        newParGroup[i].clampMax = par.clampMax
                        newParGroup[i].normMin = par.normMin
                        newParGroup[i].normMax = par.normMax
            except Exception as e:
                print(f"Error processing {parGroup.name}: {e}")

        # Process single-value parameters individually
        for par in child_comp.customPars:
            if par.style not in ['RGBA', 'XYZ', 'UV', 'XY', 'RGB']:
                try:
                    newPar = getattr(newPage, f'append{par.style}', newPage.appendFloat)(par.name, label=par.label)
                    newPar.bindExpr = f'op("{child_comp.path}").par.{par.name}'
                    newPar.default = par.default
                    newPar.min = par.min
                    newPar.max = par.max
                    newPar.clampMin = par.clampMin
                    newPar.clampMax = par.clampMax
                    newPar.normMin = par.normMin
                    newPar.normMax = par.normMax
                except Exception as e:
                    print(f"Error processing {par.name}: {e}")

    return