# HELP_ Python Primer page 57_ Geodesiccurve

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

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

I think you need to change this row:

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)        length = newlength

to

if abs(newlength - length):
length = newlength

Hi, Myongki, did you manage to figure out the problem? I am having the same issue at the exact line.
"Message: unsupported operand type(s) for -: ‘NoneType’ and ‘NoneType’

Any updates on this? I’m hung up at the same place as well. NoneType means it’s not returning a value, right?

Same spot, same problem… getting a headache of trying to find a solution.

def geodesicfit(vertices, surface_id, tolerance):
length = polylinelength(vertices)
tolerance = rs.UnitAbsoluteTolerance() / 10
while True:
vertices = smoothpolyline(vertices)
vertices = projectpolyline(vertices, surface_id)
newlength = polylinelength(vertices)
if abs(newlength-length)<tolerance:
return vertices

shows the same error:
Message: unsupported operand type(s) for -: ‘NoneType’ and ‘NoneType’

Traceback:
line 65, in geodesicfit, “E:\Rodolfo\ESTUDO\PYTHON\PYTHON101\Pag57_Geodesig.py”
line 81, in geodesiccurve, “E:\Rodolfo\ESTUDO\PYTHON\PYTHON101\Pag57_Geodesig.py”
line 93, in , “E:\Rodolfo\ESTUDO\PYTHON\PYTHON101\Pag57_Geodesig.py”

Looks like the PolylineLength() function does not return any value.
Hence the newlength and length variables get a None value.

This tutorial seems a not so accurate ‘translation’ of the VBScript one.

I’d suggest to first learn the Python language from one , or more, of the several texts and books available.
And only then come back and learn the rhinoscriptsyntax module about using Python in Rhino scripts.
( Just my humble opinion )

1 Like