Automatic Unweld Vertices

Hi

I’m trying to create the creases in the mesh automatically using a curve as a guide. But creases are created randomly. What might be missing?

The test Rhino file is attached

import scriptcontext as sc
import rhinoscriptsyntax as rs
import Rhino
from System.Drawing import Bitmap
import System
from System.Collections.Generic import *
import Rhino.Geometry as rg
from System import Array
import System.Guid

mesh01 = rs.GetObject("Select mesh", rs.filter.mesh)
mesha = rs.coercemesh(mesh01)
crv = rs.coercecurve(rs.GetObject("Select curve", rs.filter.curve))

pts = rs.MeshVertices(mesh01)
map = rs.MeshFaceVertices(mesh01)

pts_crv = rs.DivideCurve(crv, 100, False, True)

caps = []
for i in range(0, len(pts_crv)):
	for j in range(0, len(pts)):
		if rs.Distance(pts_crv[i], pts[j]) < 0.2:
			caps.append(j)

cap = list(set(caps))

pythonIntegers = cap
dotNetIntegers = Array[int](pythonIntegers)

mesh = Rhino.Geometry.Mesh()

for v in range(0, len(pts)): mesh.Vertices.Add(pts[v])
for m in range(0, len(map)): mesh.Faces.AddFace(map[m][0], map[m][1], map[m][2], map[m][3])

mesh.UnweldVertices(dotNetIntegers, False)
mesh.Normals.ComputeNormals()
mesh.FaceNormals.ComputeFaceNormals()
mesh.Compact()
sc.doc.Objects.AddMesh(mesh)
rs.HideObject(mesh01)
sc.doc.Views.Redraw()

brecha.3dm (76.8 KB)

crease_test.py (1.1 KB)