@Gijs wrote:
as an exercise, I've made a curve on surface script that rebuilds the curve while drawing, and gives the user the option to change number of points during the command.
I've taken the approach to add an empty point to the picked points that gets overriden by the dynamicdraw function CurrentPoint. Everything seems to work except I can't solve the issue that stops the dynamic draw from drawing the curve as soon as the CurrentPoint is equal to the last picked point.
I was able to solve the issue for the 'baked curve' by testing the last point to the previous point and remove it, but for the dynamic draw routine, I can't figure out how to do that. Any pointers?the script:
import Rhino import rhinoscriptsyntax as rs from System.Drawing import Color import scriptcontext as sc def DynamicCrvOnSrf(): def drawMyCurve(sender,e): points[-1]=e.CurrentPoint#change last point to CurrentPoint curve=rhsrf.InterpolatedCurveOnSurface(points,0.01) nc = curve.ToNurbsCurve() ptCount=optInt.CurrentValue nc=nc.Rebuild(ptCount,3, True) ncpoints = [nc.Points[i].Location for i in xrange(nc.Points.Count)] e.Display.DrawCurve(nc, Color.LightCyan,2) e.Display.DrawPoints(ncpoints,Rhino.Display.PointStyle.Simple,5,Color.Cyan) e.Display.DrawPoints(points,Rhino.Display.PointStyle.X,1,Color.Blue) def getPoint(): while True: result = gp.Get() if result == Rhino.Input.GetResult.Point: gp.SetCommandPrompt("Next point") pt=gp.Point() newpoint=rs.AddPoint(pt) snapPoints.append(newpoint) #append first picked point if points==[]: points.append(pt) #check if next picked point is same as previous if len(points)>1: a=round(points[-1].X,2) b=round(points[-2].X,2) if a==b: del points[-1] #add empty point to list #will get assigned in drawMyCurve() points.append(Rhino.Geometry.Point3d) gp.DynamicDraw+=drawMyCurve #recursion: getpoint calling itself if a point has been picked: getPoint() elif result == Rhino.Input.GetResult.Option: #go back to point selection mode getPoint() elif result == Rhino.Input.GetResult.Undo: del points[-2] rs.DeleteObject(snapPoints[-1]) getPoint() #pressing spacebar, enter elif result == Rhino.Input.GetResult.Nothing and len(points)>2:#2 picked points +1 temporary point #remove last added preview point del points[-1] ptCount=optInt.CurrentValue rs.DeleteObjects(snapPoints) newcrv=rs.AddInterpCrvOnSrf(srf, points) rs.RebuildCurve(newcrv,3,ptCount) sc.doc.Views.Redraw() #pressing esc else: rs.DeleteObjects(snapPoints) break srf=rs.GetObject("Select surface to draw curve on", rs.filter.surface) if srf==None: return rhsrf=rs.coercesurface(srf) gp=Rhino.Input.Custom.GetPoint() gp.SetCommandPrompt("Start of Curve") gp.Constrain(rhsrf, False) gp.AcceptNothing(True) gp.AcceptUndo(True) Rhino.ApplicationSettings.SmartTrackSettings.UseSmartTrack=False points=[] snapPoints=[] optInt=Rhino.Input.Custom.OptionInteger(20,4,100) gp.AddOptionInteger("ptCount",optInt) getPoint() if( __name__ == "__main__" ): DynamicCrvOnSrf()
Posts: 9
Participants: 2