Hello all,
I am having some trouble with a python script I and a colleague are writing that would take in a mesh and iterate through the all the vertices and get them to recognize their neighbors so as to be able to act on them. For some reason it seems as though I am getting double the perceived number of connections.
It would be monumentally helpful if you could glance over my code and tell me what might be causing this issue.
Here is the python script:
import rhinoscriptsyntax as rs
import Rhino
import scriptcontext
#Written By Matthew Austin
#EndOfLine.info
#ComponentToMakeUniqueMeshEdges
def GetEdges(x):
b = x.Faces
edges = []
for i in range(b.Count):
face = b.GetFace(i)
if face.IsTriangle:
A = face.A
B = face.B
C = face.C
if A < B:
edges.append((A,B))
else:
edges.append((B,A))
if B < C:
edges.append((B,C))
else:
edges.append((C,B))
if C < A:
edges.append((C,A))
else:
edges.append((A,C))
if face.IsQuad:
A = face.A
B = face.B
C = face.C
D = face.D
if A < B:
edges.append((A,B))
else:
edges.append((B,A))
if B < C:
edges.append((B,C))
else:
edges.append((C,B))
if C < D:
edges.append((C,D))
else:
edges.append((D,C))
if D < A:
edges.append((D,A))
else:
edges.append((A,D))
edges.sort()
uniqueEdges = []
count = 1
range(len(edges))
while count < len(edges):
scriptcontext.escape_test()
if edges[count] == edges[count-1]:
edges.pop(count)
else:
count = count + 1
return edges
class SuperVertex:
myPosition = 0
SuperFriends = []
myNeighbours = []
def __init__(self, vertex):
self.myPosition = vertex
SuperVertex.SuperFriends.append(self)
def getNeighbour(self, neighbour):
self.myNeighbours.append(neighbour)
edges = GetEdges(x)
verticies = x.Vertices
for i in range(verticies.Count):
SuperVertex(verticies[i])
for i in range(len(edges)):
vertex0 = edges[i][0]
vertex1 = edges[i][1]
print "(" + str(vertex0) + "," + str(vertex1) + ")"
vertex0 = SuperVertex.SuperFriends[vertex0]
vertex1 = SuperVertex.SuperFriends[vertex1]
vertex0.getNeighbour(vertex1)
vertex1.getNeighbour(vertex0)
print len(SuperVertex.SuperFriends[27].myNeighbours)