Maxon Developers Maxon Developers
    • Documentation
      • Cinema 4D Python API
      • Cinema 4D C++ API
      • Cineware API
      • ZBrush GoZ API
      • Code Examples on Github
    • Forum
    • Downloads
    • Support
      • Support Procedures
      • Registered Developer Program
      • Plugin IDs
      • Contact Us
    • Categories
      • Overview
      • News & Information
      • Cinema 4D SDK Support
      • Cineware SDK Support
      • ZBrush 4D SDK Support
      • Bugs
      • General Talk
    • Unread
    • Recent
    • Tags
    • Users
    • Login

    Drive one parameter with another and vice versa

    Cinema 4D SDK
    python
    2
    3
    697
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • merkvilsonM
      merkvilson
      last edited by

      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?

      1 Reply Last reply Reply Quote 0
      • a_blockA
        a_block
        last edited by

        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

        1 Reply Last reply Reply Quote 2
        • merkvilsonM
          merkvilson
          last edited by

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

          1 Reply Last reply Reply Quote 0
          • First post
            Last post