@luisseyfer wrote:
Hello,
I am trying to create a Component
wich snaps the ends of an open curve in the middle of the endpoints to close it.
Since the curve is an assambly of various bended segments wich has some sharp edges I explode it first.
Then I rebuild the start- and endsegments.
Now I want to rejoin everything, but get an error.import rhinoscriptsyntax as rs ############################################## ############################################## # Ensure variable is defined try: tol except NameError: tol = None # Test whether variable is defined to be None if tol is None: tol = 0 ############################################## ############################################## #get endpoints and the middle between them - Point if rs.IsCurve(opCrv): # and not rs.IsCurveClosed(opCrv) and rs.IsCurveClosable( opCrv, tol ): cePt = rs.CurveEndPoint(opCrv) csPt = rs.CurveStartPoint(opCrv) else: print "not an open curve in respect to the given tolerance" dist = rs.Distance(cePt, csPt) nePt = cePt - csPt nePt = rs.VectorUnitize(nePt) nePt *= dist/2 midVec = rs.VectorCreate(cePt, csPt) midVec = rs.VectorDivide(midVec,2) matrix = rs.XformTranslation(midVec) nePt = rs.PointTransform(csPt, matrix) ############################################## #get points of start and end segment for rebuild segCrvList = rs.ExplodeCurves(opCrv) #gives a list sSeg = segCrvList[0] eSeg = segCrvList[len(segCrvList)-1] sSegPt = rs.CurveEditPoints(sSeg) ssSegPt = sSegPt[0] eSegPt = rs.CurveEditPoints(eSeg) eeSegPt = eSegPt[len(eSegPt)-1] #replace points and rebuild of segments sSegPt[0] = eSegPt[len(eSegPt)-1] = nePt sSeg = rs.AddInterpCurve(sSegPt) eSeg = rs.AddInterpCurve(eSegPt) #replace segments and join all into closed curve segCrvList[0] = sSeg segCrvList[len(segCrvList)-1] = eSeg clCrv = rs.JoinCurves( segCrvList, delete_input=True, tolerance=tol)
Error:
0. Runtime error (NullReferenceException): Object reference not set to an instance of an object. Traceback (most recent call last): SystemError: Object reference not set to an instance of an object.
What is wrong?
Posts: 11
Participants: 3