SOLVED Set Tracers "trace link" (inExclude) field from python tag

Hi
Im trying to set the Tracer objects "Trace link" inExclude list from a python tag.
I dont get any errors and the GetObjectCount method returns the correct number of objects, but none are visible in the list itself. Any help appreciated. See attached file for example.

import c4d

def main():
    # Get userdata from parent
    root = op.GetObject().GetUp()[c4d.ID_USERDATA,1]

    # Get first joint
    hipJoint = root.GetDown()
    # Get second joint
    kneeJoint = hipJoint.GetDown()
  
    # Get the tracers inExclude field
    tracerList = op.GetObject()[c4d.MGTRACEROBJECT_OBJECTLIST]

    # Insert hip
    tracerList.InsertObject(hipJoint, 1)
    # Insert knee
    tracerList.InsertObject(kneeJoint, 1)
    
    # Returns 2 but none are visible in the tracers inExclude field
    print tracerList.GetObjectCount()

Regards
Bonsak

0_1542205877232_inexclude-python-update.c4d

Hello,

when you "get" the InExclude list in Python, you get a copy of the value, not a reference.

After editing the copy you have to store the new value again in the original object:

# get data
tracerList = op.GetObject()[c4d.MGTRACEROBJECT_OBJECTLIST]

# modify data

#store data
op.GetObject()[c4d.MGTRACEROBJECT_OBJECTLIST] = tracerList

But remember: a tag is executed every time the scene is evaluated. So the objects are added to the list again and again. You could maybe check if the list is empty and return if that is not the case:

if tracerList.GetObjectCount() > 0:
    return

Please also use the Q&A system to mark your threads as questions.

Best wishes,
Sebastian

Awesome! Thanks.

Regards
Bonsak