I am following Rhino 5 Python Primer regarding Geodesic curve.
I am struggling to solve errors like this
"Message: unsupported operand type(s) for -: ‘NoneType’ and 'NoneType’
this is my code.
import rhinoscriptsyntax as rs
def SubDividePolyline(arrV):
arrSubD =
for i in range(0, len(arrV)-1):
arrSubD.append(arrV[i])
arrSubD.append([arrV[i][0] +arrV[i+1][0]] / 2.0, [arrV[i][1] +arrV[i+1][1]] / 2.0, [arrV[i][2] +arrV[i+1][2]] / 2.0 )
arrSubD.append(arrV[len(arrV)])
return arrSubD
def getr2pathonsurface(surface_id, segments, prompt1, prompt2):
start_point = rs.GetPointOnSurface(surface_id, prompt1)
if not start_point: return
end_point = rs.GetPointOnSurface(surface_id, prompt2)
if not end_point: return
if rs.Distance(start_point, end_point) == 0.0: return
uva = rs.SurfaceClosestPoint(surface_id, start_point)
uvb = rs.SurfaceClosestPoint(surface_id, end_point)
path = []
for i in range(segments):
t = i / segments
u = uva[0] + t*(uvb[0] - uva[0])
v = uva[1] + t*(uvb[1] - uva[1])
pt = rs.EvaluateSurface(surface_id, u, v)
path.append(pt)
return path
def smoothpolyline(vertices):
smooth =
smooth.append(vertices[0])
for i in range(1, len(vertices)-1):
prev = vertices[i-1]
this = vertices[i]
next = vertices[i+1]
pt = (prev+this+next)/3.0
smooth.append(pt)
smooth.append(vertices[len(vertices)-1])
return smooth
def projectpolyline(vertices, surface_id):
polyline =
for vertex in vertices:
pt = rs.BrepClosestPoint(surface_id, vertex)
if pt : polyline.append(pt[0])
return polyline
def PolylineLength(arrVertices):
PolylineLength = 0.0
for i in range(0, len(arrVertices)-1):
PolylineLength = PolylineLength + rs.Distance(arrVertices[i], arrVertices[i+1])
def geodesicfit(vertices, surface_id, tolerance):
length = PolylineLength(vertices)
while True:
vertices = smoothpolyline(vertices)
vertices = projectpolyline(vertices, surface_id)
newlength = PolylineLength(vertices)
if abs(newlength - length)<tolerance: return vertices
length = newlength
def geodesiccurve():
surface_id = rs.GetObject(“Select surface for geodesic curve solution”, 9, True, True)
if not surface_id: return
vertices = getr2pathonsurface(surface_id, 10, "Start of geodes curve", "End of geodes curve")
if not vertices : return
tolerance = float(rs.UnitAbsoluteTolerance()) / 10.0
length = 1e300
newlength = 0.0
while True:
print ("Solving geodesic fit for %d samples" % len(vertices))
vertices = geodesicfit(vertices, surface_id, tolerance)
newlength = PolylineLength(vertices)
if abs(newlength - length)<tolerance: break
if length(vertices)>1000: break
vertices = SubDividePolyline(vertices)
length = newlength
rs.AddPolyline(vertices)
print "geodesic curve added with length: ", newlength
if name == “main” :
geodesiccurve()
I went over scripts several times but I have no idea.
I would be much appreciated if you share your know-how on this.
thanks