Hi, i wrote a script that takes vetex from a mesh and makes lists of points which have the same coordinates in X and lists of points which have the same coordinates in Y. Lists are used then to make curves. finally, it is supposed to make a network of curves in Y and X which are “sticky” to the initial mesh. But the script takes too long. I haven’t found any infinite loop so i don’t know what’s wrong.:mad:
Is anybody can tell me how to fix it?
import Blender
from Blender import Mesh, Object, Scene, NMesh, Curve, CurNurb
ob = Blender.Object.GetSelected()[0]
me = NMesh.GetRawFromObject(ob.getName())
VertList= []
ListSameX = []
ListSameY = []
for v in me.verts:
x = v.co[0]
y = v.co[1]
z = v.co[2]
w = 2.0
Vco = [x,y,z,w]
VertList.append(Vco)
del Vco
for coorda in VertList:
SameX=[]
SameY=[]
for coordb in VertList:
if coordb not in SameX:
if coorda[0] == coordb[0]:
SameX.append(coordb)
if coordb not in SameY:
if coorda[1] == coordb[1]:
SameY.append(coordb)
point0 = SameX[0]
tamponSameX = [point0]
while point0:
dist_point = {}
distances = []
for coordb in SameX:
d = ((coordb[1]-point0[1])**2+(coordb[2]-point0[2])**2)**0.5
if d == 0:
pass
else:
dist_point[d] = coordb
distances.append(d)
if distances == []
del distances
else:
distances.sort()
dmini = distances[0]
next_point = dist_point.get(dmini)
tamponSameX.append(next_point)
SameX.remove(point0)
point0 = next_point
if len(SameX) == 0:
point0 = False
SameX = tamponSameX[:]
point0 = SameY[0]
tamponSameY = [point0]
while point0:
dist_point = {}
distances = []
for coordb in SameY:
d = ((coordb[0]-point0[0])**2+(coordb[2]-point0[2])**2)**0.5
if d == 0:
pass
else:
dist_point[d] = coordb
distances.append(d)
if distances == []:
del distances
else:
distances.sort()
dmini = distances[0]
next_point = dist_point.get(dmini)
tamponSameY.append(next_point)
SameY.remove(point0)
point0 = next_point
if len(SameY) == 0:
point0 = False
SameY = tamponSameY[:]
ListSameX.append(SameX)
ListSameY.append(SameY)
for SameX in ListSameX:
cu = Curve.New()
cu.appendNurb(SameX[0])
cu_nurb = cu[0]
SameX.remove(SameX[0])
for coordb in SameX:
cu_nurb.append(coordb)
if cu_nurb.CurNurb.isCyclic() == False:
cu_nurb.CurNurb.isCyclic = True
ob= Object.New('Curve')
ob.link(cu)
scn= Scene.GetCurrent()
scn.link(ob)
ob.layers= [6]
for SameY in ListSameY:
cu = Curve.New()
cu.appendNurb(SameY[0])
cu_nurb = cu[0]
SameY.remove(SameY[0])
for coordb in SameY:
cu_nurb.append(coordb)
if cu_nurb.CurNurb.isCyclic() == False:
cu_nurb.CurNurb.isCyclic = True
ob= Object.New('Curve')
ob.link(cu)
scn= Scene.GetCurrent()
scn.link(ob)
ob.layers= [7]
Blender.Redraw()