How to use RebuildCrvNonUniform on multiple closed curves automatically?

I would like to use the function RebuildCrvNonUniform on all closed curves in a drawing in Rhino5. But if I select all curves at once and perform that function, all curves get as much control points as is needed for the most complicated curve which is way too much for most of the curves. So I have to manually select each curve separately and perform that function on that single curve. How do I create a rhinoscript that iterates over all the curves in a drawing and performs this function on each of them?

something like this should work

import rhinoscriptsyntax as rs

curves = rs.GetObjects("select curves to rebuild", 4)
rs.UnselectAllObjects()
if curves:
    for curve in curves:
        rs.SelectObject(curve)
        rs.Command("-RebuildCrvNonUniform r 0.1 m 100 DeleteInput=yes enter") 
        rs.UnselectAllObjects()
1 Like

I have tried to use this piece of code by pasting it in RhinoScript Editor and run it, but unfortunately it then says: Error: expected end of statement at line 1, char 26 and I do not know how to adapt the code (I am totally new in scripting in Rhino).

try EditPythonScript instead

Yes it works now. I did change the parameters r 0.1 m 100 to r 0.2 m 10000 to suit my needs, but this piece of script is going to save me a lot of time. Thank you for that.