Help : rs.CoerceMesh(mesh_id) and replace vertices

Hi, I have made a tool to trace over another mesh, with the option to continue on that start_mesh later on.
It’s quite simple and uses the points to make a mesh patch with the command patch=Rhino.Geometry.Mesh.CreatePatch(OuterPolyLine,tol,None,innerBoundaryCurves,innerBothSideCurves,InnerPts,Trimback,Divisions)

Right now I generate a new mesh and delete the old for every step, but I would like to replace the start_mesh instead, so it keeps it’s properties, but I seem to have a problem.

I traceMesh = rs.coercemesh(mesh_id) and read out the vertices for the new mesh to start with, but when I try to replace the traceMesh.Vertices = patch.Vertices I get this error:

Message: can’t assign to read-only property Vertices of type 'Mesh’

What do I have to do to the coerced mesh to be able to replace the vertice list?
I will do the same with the face list too of course.

I tried to .Clear the lists and then add all the items from the other list, but it seems Clear doesn’t work and it just makes a messy mesh… :slight_smile:

Clear and Add is one way. The other would be to set each existing vertex to a different location.

Thanks, but the list length is just as long after mesh.Vertices.Clear is ran and grows when I mesh.Vertices.Add to it…

The thing is that I add new points both around and within the mesh, so I need the new set of vertices and faces that the patch has.

I tried this:

            if mesh:
                print "replacing mesh"
                for vertex in patch.Vertices:
                for face in patch.Faces:

And the result is a new, messy, twice as dense mesh.
(I tried both Clear and Delete stuff in the example above)

You need to add parentheses for function calls. For example




I am so used to being spoiled by the script editor telling me what I do wrong, that when it doesn’t I think I did it right…

You saved the day again!

Unfortunately, that is legitimate syntax as you can set variables to functions. In that case an editor won’t bark at you.

Happy to help. I like the easy ones😉

And I am good at still failing on the easy ones, even after all these years :wink:
Thanks a million! Now I can continue to build on a textured mesh, wohoo! :smiley:

1 Like