Master Slider Python Tag

This is simple Python Tag example that daisy chains children’s specific parameter and then you can control sequentially linked parameters. In this example there is a couple Sweep Objects and their ‘End Growth’ parameter is linked to the Master Slider.

Master Slider

If you have for example 20 children and want that 6 first are 100%, you should use following formula in theMaster Slider’s input field:

(100 / [childrencount]) * [nth child]

So in this case we would input: (100 / 20) * 6. It is recommended that linked parameter uses float values. If parameter uses different value than percentage, change “maxValue” variable accordingly.

import c4d
from c4d import utils as u

def main():
    slider = op[c4d.ID_USERDATA,1] # User Data: 'Slider'
    obj = op.GetObject() # Get object
    children = obj.GetChildren() # Get children list
    count = len(children) # Count of children
    maxValue = 1 # Parameter's maximum value (In this example it's 100%)
    step = (1 / float(count)) # Step size
    for i, child in enumerate(children): # Iterate through children
        if i == 0: # If first item
            r = u.RangeMap(slider, 0, step, 0, maxValue, True) # Map range
        else: # If anything else but first item
            r = u.RangeMap(slider, step*i, step*(i+1), 0, maxValue, True) # Map range
        child[c4d.SWEEPOBJECT_GROWTH] = r # Manipulate child's parameter

Originally I builded this setup for “Connect Spheres” Python Generator. It uses same algorithm in “Sequence” mode.

master_slider_python_tag.c4d

Master Slider 2

Thanks to @cristobalvila for requesting a delay function, I made Master Slider 2. There is options to offset slaves with ‘delay’ slider and remap output values with spline data.

import c4d
from c4d import utils as u

def main():
    try: # Try to execute following code
        slider = op[c4d.ID_USERDATA,1] # User Data: 'Slider'
        delay = op[c4d.ID_USERDATA,3] # User Data: 'Delay'
        spline = op[c4d.ID_USERDATA,4] # User Fata: 'Spline'
        obj = op.GetObject() # Get object
        children = obj.GetChildren() # Get children list
        count = len(children) # Count of children
        maxValue = 400 # Parameter's maximum value (In this example it's 100%)
        step = (1 / float(count)) # Step size
        for i, child in enumerate(children): # Iterate through children
            z = (delay*count) + (slider-delay)
            step = u.RangeMap(slider, 0, 1, 0, z, False)
            step = step-(delay*i)
            r = u.RangeMap(step, 0, 1, 0, maxValue, True, spline)
            child[c4d.PRIM_RECTANGLE_WIDTH] = r # Manipulate child's parameter
    except: # If comething went wrong
        pass # Do nothing

I’ll keep these files separated, since they operate a bit differently.

Updated 30/05/2019
> Added Master Slider 2 setup

master_slider_2_python_tag.c4d

Cinema 4D, Python, Tag