What is wrong with my script?

Recently I wrote a script that is going to act as a function for a bigger project, when I run this script for some reason it never stops. I was wondering from a sheer coding perspective could someone tell me where exactly my script is continuously looping, and why?

def groupmouths(elist):
	edgelist = []
	mesh = elist[1]
	elist = elist[0]
	for i in elist:
		used = 0
		for e in edgelist:
			for f in e:
				if i.key[0] in f.key or i.key[1] in f.key:
					used = 1
		if used == 0:
	return[edgelist, mesh]

Yes e.apend(i) makes e longer and longer, so it stops ‘never’

Well… I was hard to figure out what this script really does… :eek:

I think it is to produce a list of adjacent edges in a mesh… If so, there is a better way to do that :wink:

Your input parameter seems to contain data for two elements - a mesh and indices of edges of the same mesh… Then, your edgelist is ever growing and after some loops it is also hard to get processed in reasonable time as PKHG mentioned.


hmmm, you are right in thinking that the script is meant to come up with a list of adjacent edges, but why would the list continue growing forever, it only appends i for values in elist, checking if they already exist in edgelist.
And Abidos, my script’s input is a series of edges, the goal is then to group them into sublists of connected edges, for example: edgelist = [[edge1,edge2,edge3,edge4],[edge5,edge6,edge7],[edge8,edge9,edge10,edge11,edge12]]
do you have a solution of how to do this?

You should never use this kind of constructions:

for f in e:

This means you are looping over a changing list of objects, which leads to undefined results.

You could go around the problem this way:

>>> e=[1,2,3]
>>> for i in e[:]:
...   e.append(4)
>>> e
[1, 2, 3, 4, 4, 4]

One of functions in my modules (see here) is about info on which edges in a mesh are connected at which vertex. Obviously, adjacent edges, right?? Extracted from the module it is:

def Make_vie(me):
    vie = dict([(v.index,[]) for v in me.verts])
    for ed in me.edges:
        for key in ed.key:
    return vie

resulting in a dictionary like this (the result for the default cube):

vie = {0: [1, 2, 9], 1: [0, 1, 8], 2: [0, 3, 10], 3: [2, 3, 11], 4: [4, 7, 9], 5: [4, 5, 8], 6: [5, 6, 10], 7: [6, 7, 11]}

In the modules I have procs for adjacent faces (fif), verts in each face (fiv), edges in each face (fie) and such… This helps a lot while analyzing a mesh. :spin: