Hey,
It would be great if we could get the ExtendCurveOnSurface function implemented in rhinoscriptsyntax library.
I have worked up an example using Rhino.Geometry and it seems to work fine for me. The rs.coercecurve would need to be changed to rhutil.coercecurve and some if/elifs for selecting which end to extend but the core functions all seem to be present for this to be added.
import rhinoscriptsyntax as rs
import Rhino
from scriptcontext import doc
def ExtendCurveOnSurface(Crv,Srf):
Surface=rs.coercesurface(Srf)
Curve=rs.coercecurve(Crv)
Extended=Curve.ExtendOnSurface(Rhino.Geometry.CurveEnd.Both,Surface)
if Extended!=None:
doc.Objects.Replace(Crv,Extended)
doc.Views.Redraw()
Here is a bit of sample code (obviously more/better UI could be added):
import rhinoscriptsyntax as rs
import scriptcontext as sc
import Rhino
def ExtendCrvOnSrf(crv,crv_end,srf):
return crv.ExtendOnSurface(crv_end,srf)
def ClosestEnd(crv,pick_pt):
#determines the closest curve end to the pick point
dom=crv.Domain
rc,par=crv.ClosestPoint(pick_pt)
if rc:
start_len=crv.GetLength(Rhino.Geometry.Interval(dom.T0,par))
end_len=crv.GetLength(Rhino.Geometry.Interval(par,dom.T1))
if start_len<end_len:
return Rhino.Geometry.CurveEnd.Start
else:
return Rhino.Geometry.CurveEnd.End
def TestFunction():
crvID=rs.GetObject("Select curve to extend",4)
if not crvID: return
srfID=rs.GetObject("Select surface that curve is on",8)
if not srfID: return
pick_pt=rs.GetPointOnCurve(crvID,"Pick end of curve to extend")
if not pick_pt: return
crv=rs.coercecurve(crvID)
srf=rs.coercesurface(srfID)
#determine if pick point was closer to start or end
crv_end=ClosestEnd(crv,pick_pt)
if crv_end:
ext_crv=ExtendCrvOnSrf(crv,crv_end,srf)
if ext_crv:
sc.doc.Objects.AddCurve(ext_crv)
rs.DeleteObject(crvID)
TestFunction()