 # Iteration over non-sequence of type NoneType

Hello,
i get this error “Iteration over non-sequence of type NoneType” all the time, and i dont know why. I know that the problem lies in the line 78 but i am a beginner and copied the code from the professor. So i dont know exactly what im doing and therefor i dont know whats wrong.

``````for face_index in vertex_faces:
``````

This is the problematic line.
Below is the code.

Best whishes to all of you. Hope somebody can help me.

import rhinoscriptsyntax as rs
import math
import Rhino as rc
import Rhino

a=400
b=100
c=1.5
d=1
f=0
n_u=16
n_v=16
u_closed=True
v_closed=True

edge_list =
point_list =
polygon_list =

origin = rc.Geometry.Point3d(0,0,0)

rs.EnableRedraw(False)

#generate the points
for i in range(0,n_v+1):
v = i / n_v
for j in range(0,n_u+1):
u = j / n_u
x = 10*((0.1+math.sin(3i/160math.pi))math.cos(cj/bmath.pi))
y = 10
((0.1+math.sin(3i/160math.pi))math.sin(cj/bmath.pi))
z = 10
(0.1+j/a+(0.3-0.231*i/40)math.cos(i/20math.pi))
point_list.append ([x,y,z])

# generate the polygons & edges

for i in range(0,n_v):
for j in range(0,n_u):
if (not u_closed):
p0 = i*(n_u+1)+j
p1 = i*(n_u+1)+j+1
if (not v_closed):
p2 = (i+1)(n_u+1)+j+1
p3 = (i+1)
(n_u+1)+j
else:
p2 = ((i+1) % n_v)(n_u+1)+j+1
p3 = (i+1)
(n_u+1)+j
else:
p0 = i*(n_u)+j
p1 = i*(n_u)+((j+1) % n_u)
if (not v_closed):
p2 = (i+1)(n_u)+((j+1) % n_u)
p3 = (i+1)
(n_u)+j
else:
p2 = ((i+1) % n_v)(n_u)+((j+1) % n_u)
p3 = ((i+1) % n_v)
(n_u)+j
polygon_list.append ([p0,p1,p2,p3])
edge_list.append ([p0,p1])
edge_list.append ([p3,p0])
if (not u_closed):
if (j == n_u-1):
print “u edge”
edge_list.append([p1,p2])
if (not v_closed):
if (i == n_v-1):
print “v edge”
edge_list.append([p2,p3])

face_normals = rs.MeshFaceNormals(mesh)
point_normals =

for k in range(0,len(point_list)):
vertex_faces = rs.MeshVertexFaces(mesh, k)
p_normal = Rhino.Geometry.Vector3d(0,0,0)
for face_index in vertex_faces:
p_normal = p_normal + face_normals[face_index]
p_normal = rs.VectorUnitize(p_normal)
point_normals.append(p_normal)

#rs.ScaleObject(Pasta,origin,[d,d,d])
#rs.RotateObject(Pasta,origin,f)

points = point_list
edges = edge_list

rs.EnableRedraw(True)

geometry = ghdoc.Objects.Geometries

Haven’t actually checked the script, but generically when you get that error message, you are trying to loop through a list you think exists, but actually doesn’t or is empty (and is therefore `None`).

So in this case, I would look at why `vertex_faces` ends up being `None` in the lines just before the error

``````for k in range(0,len(point_list)):
vertex_faces = rs.MeshVertexFaces(mesh, k)
``````

Maybe k ends up at a value higher than the number of mesh vertices…

–Mitch

Hey Mitch,

thanks for helping. I think you are right. If i change k to a low number the code runs. Do you have an idea how i can change the code to make it variable?
Sry for the dumb questions.

Best whises

Well, that means that the length of your point_list variable is longer than the list of your mesh vertices. I would first check why that is, what is the relation between your point list and the mesh vertex list.

You can always limit the number of indices checked to the number of vertices that actually exist by using something like `vertex_count=rs.MeshVertexCount(mesh)` which will give you the number of vertices in your mesh:

``````for k in range(vertex_count):
vertex_faces = rs.MeshVertexFaces(mesh, k)
``````

however, I don’t know if that works for the rest of the script…

Thanks alot! I hope you have good day Sir.