SOLVED Drive one parameter with another and vice versa

Hello PluginCafe :)

I want to know how to drive one parameter with another and vice versa.
Let's assume I have a Tag Plugin which is assigned to the cube object and tracks its number of segments on X and Y axes. How to control X value if a user interacts with the Y parameter and drive Y value if a user interacts with X parameter?

Hi,

the tag can not directly react to parameter changes of the host object. But instead you could store the parameter values somewhere, in my example I'll use user data on the tag, and then act upon value changes in the tags Execute() function.

Here's a small example, what I mean:

def main():
    # Example: Linking the x and y size of a cube.
    # In this example using [c4d.ID_USERDATA,1] and
    # [c4d.ID_USERDATA,2] to remember last parameter values

    hostObj = op.GetObject()

    # awkward initialization, do something better...
    if op[c4d.ID_USERDATA,1] < -100000:
        op[c4d.ID_USERDATA,1] = hostObj[c4d.PRIM_CUBE_LEN].x
        op[c4d.ID_USERDATA,2] = hostObj[c4d.PRIM_CUBE_LEN].y
        return
    
    # actual parameter linking
    if op[c4d.ID_USERDATA,1] != hostObj[c4d.PRIM_CUBE_LEN].x:
        hostObj[c4d.PRIM_CUBE_LEN] = c4d.Vector(hostObj[c4d.PRIM_CUBE_LEN].x,
                                                hostObj[c4d.PRIM_CUBE_LEN].x * 2.0,
                                                hostObj[c4d.PRIM_CUBE_LEN].z)
    elif op[c4d.ID_USERDATA,2] != hostObj[c4d.PRIM_CUBE_LEN].y:
        hostObj[c4d.PRIM_CUBE_LEN] = c4d.Vector(hostObj[c4d.PRIM_CUBE_LEN].y / 2.0,
                                                hostObj[c4d.PRIM_CUBE_LEN].y,
                                                hostObj[c4d.PRIM_CUBE_LEN].z)

    # store new values for next run
    op[c4d.ID_USERDATA,1] = hostObj[c4d.PRIM_CUBE_LEN].x
    op[c4d.ID_USERDATA,2] = hostObj[c4d.PRIM_CUBE_LEN].y

And here's the scene: synced_params.c4d

Cheers,
Andreas

Thanks, Andreas! 💙
This is a really interesting approach.