Best way to add control points to a curve?

I’m using ghpython to write a visitors’ path simulation.
I have a timer that’s linked to the python component and it updates all the visitors’ positions and links their past points together to create paths (curves).
The code goes something like this:

#for a single tourist, updates his/her position
#then update the curve
tourist.trail = rs.AddPolyline(tourist.positionList)

Right now I’m faced with the problem that I am adding an entirely new curve for every visitor per update, instead of updating the existing curve. It caused a lot of performance issues. I have tried different solutions including setting the trail to None, or using rs.DeleteObject and a couple of other things. None of them worked.

Thanks for reading and I will really appreciate it if you could offer some insight.

Instead of using rs.AddPolyline and writing those polylines to the rhinodoc why don’t you just append to the output of your ghpython component? This way your geometry stays ‘virtual’ and you should see a significant performance increase.

if for some reason rs.AddPolyline is mandatory for your project, reuse the guid that gets returned to replace the already added polylines:

    if tourist.trail == None:
        tourist.trail = rs.AddPolyline(tourist.positionList)
        rs.AddPolyline(tourist.positionList, replace_id=tourist.trail)

Generally speaking, NOT adding to the rhinodoc is much faster and your use case sounds like adding those polylines after all updates are done would be sufficient.

Thank you for replying! However, this solution does not work. It gives me an error, simply as:
Runtime error (PythonException): Unable to add polyline to document

The thing is I hope to make a dynamic simulation/animation of tourists avoiding each other, going around walls, have different behavior patterns etc., in real time. That’s why I’m generating a trail for each update. I appreciate the suggestion though.

i wrote a quick sample how this works without adding to the document.

add pline (9.1 KB)

The idea is having your class store the polyline itself in its ‘Trail’ Variable and collecting the polylines from all of your class instances( tourists) into the output of the ghpython component for visualization. Adding to the rhinodoc can be done after all the updates.

A code sample of yours would be a good start to show where you could optimize things.