What is the proper way to insert new point in mesh?

image

face = Rhino.Geometry.MeshFace(0, 1, 2)

msh = Rhino.Geometry.Mesh()

msh.Vertices.Add(P0)
msh.Vertices.Add(P1)
msh.Vertices.Add(P2)
msh.Faces.AddFace(face)

a = pt_to_insert = Rhino.Geometry.Point3f(0.0,0.0,0.0)
msh.Vertices.Insert(3, pt_to_insert)

msh.Faces.Item[0].D = 4
msh.Faces.AddFace(Rhino.Geometry.MeshFace(2, 3, 4))

print msh.Faces.TriangleCount

b = msh

This above doesn’t seem to work.

Scenario:
I wish to start with a triangular single face mesh. then insert one point making another triangle.

subsequently I wish to be able to move each vertex by entering coordinates.

Thanks in advance.

This seems to work:

image

But is this the proper way?

The only problem is that you’re adding 4 points to your mesh but you’re trying to create a face with the fifth vertex (indexed 4), which obviously does not exist.
MeshFaceList.AddFace method has an overload that accepts indices directly.
MeshVertexList.Add method has an overload that accepts coordinates directly.

import Rhino
msh = Rhino.Geometry.Mesh()

msh.Vertices.Add(P0)
msh.Vertices.Add(P1)
msh.Vertices.Add(P2)

msh.Faces.AddFace(0, 1, 2)
msh.Vertices.Add(10,10,0)
msh.Faces.AddFace(1, 2, 3)

a = msh
print msh.Faces.TriangleCount
1 Like