ERROR expected ObjRef, got CurveObject

import Rhino
import scriptcontext
import System
import Rhino.UI
import Eto.Drawing as drawing
import Eto.Forms as forms
import rhinoscriptsyntax as  rs
layer_names = rs.LayerNames()
layer_objects = list(layer for layer in scriptcontext.doc.Layers if not layer.IsDeleted)
for name in layer_names:
    layer_obj = None
    for layer_obj in layer_objects:
        if layer_obj.FullPath == "MCS":
            autoMCS = scriptcontext.doc.Objects.FindByLayer(layer_obj)
            rs.ConvertCurveToPolyline (autoMCS[0], 0.1, 0.1, True, 1, 5)

TEST.3dm (49.9 KB).

Use ObjRef Constructor (RhinoObject) on your RhinoObject instances.

Note that you are doing two for loops over layer data. First over layer names, then over layer objects. Do only one.

Also, you are using only the very first object of the potentially many you find. You probably can use the idiom on autoMCS as well, make sure you convert each RhinoObject instead of just the one.

You probably meant to do the conversion to polyline inside the inner-most if so I edited your original post to have both the code block (tripple backtick), and the indented last line.

I don’t understand all that. Can you fix this code help me. Please.!!

import Rhino.DocObjects

 # ...

for crv in autoMCS:
    obref = Rhino.DocObjects.ObjRef(autoMCS)
    # now you can convert your objref into polyline