Skip to content

Instantly share code, notes, and snippets.

@pgolay
Last active March 12, 2022 00:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pgolay/c7d27755f8381386264534652a806438 to your computer and use it in GitHub Desktop.
Save pgolay/c7d27755f8381386264534652a806438 to your computer and use it in GitHub Desktop.
import Rhino
import rhinoscriptsyntax as rs
import scriptcontext as sc
"""
redistributes one curve along another by closest points.
"""
def MatchCurveStructure():
id1 = rs.GetObject("Select the reference curve", 4, preselect=True)
if not id1: return
id2 = rs.GetObject("Select the curve to change", 4)
if not id2: return
if not rs.CurveDirectionsMatch(id1, id2):
rs.ReverseCurve(id2)
crv1Geo = rs.coercegeometry (id1)
crv2Geo = rs.coercegeometry (id2)
if not crv1Geo: return
if isinstance(crv1Geo, Rhino.Geometry.BrepEdge):
crv1Geo = crv1Geo.EdgeCurve
targs = [crv2Geo.PointAtStart]
for n in range(1,crv1Geo.GrevillePoints().Count -1):
targs.append( crv2Geo.PointAt(crv2Geo.ClosestPoint(crv1Geo.GrevillePoints()[n])[1]) )
targs.append(crv2Geo.PointAtEnd)
#targs = [crv2Geo.PointAt(crv2Geo.ClosestPoint(pt)[1]) for pt in crv1Geo.GrevillePoints()]
if crv1Geo.SetGrevillePoints(targs):
newId = sc.doc.Objects.AddCurve(crv1Geo)
if newId: rs.UnselectAllObjects()
rs.SelectObject(newId)
if __name__ == "__main__":
MatchCurveStructure()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment