100,000 faces would take minutes. Growing a list one element at a time in Python gets very slow as your list gets big.
I start with a flattened list of faces, then I'm just looping on my list until I get to the end. Inside the loop looks a bit like this: normal = face.getNormal() connected = face.connectedFaces() for f in connected: # If f is already in my list, continue # Test normal.dot(f.getNormal()) and add to the end of the list if it passes That's pretty much it. I haven't needed to flatten any components (though if you find a case where you think you do, I'd advise you try to use them as they are, because a mesh component iterable is an API data structure, and flattening it into individual mesh components involves a lot of Python behind the scenes. If you want to use it on 100,000 faces and you don't want to learn how to do it in C++ (which is fair enough), maybe try the Python API. One huge advantage of the API is the array types, which manage their memory very well and can be arbitrarily grown to 100,000 or even millions of elements without slowing everything horribly like Python lists would*. The logic would be very similar (using MItMeshPolygon instead of MeshFace) and I don't think it would be much faster for smaller selections, but it could handle larger ones better. (*Alternatively you can pre-assign the size of your Python lists, and keep track of the number of used elements yourself. Sometimes that's easier.) Honestly I'm really intrigued now. Hopefully I'll have time tonight to try to make a version that can handle big numbers. On Thursday, 5 April 2018 16:29:06 UTC+10, Darby Edelen wrote: > > There are definitely some intricacies of pymel that elude me. I don't > know, for example, how to get a flattened list of connected faces without > using ls. Or perhaps I don't need a flattened list? I assume that I need to > getNormal on each face and compare against its connected faces in order to > decide which faces to extend to on the next step. Can I do that if > connectedFaces isn't giving me a flattened list? > > As for the speed at which this script and the similar built-in selection > constraints operate, they are woefully slow in comparison to the cinema 4d > tool I'm trying to emulate. I think there must be some data built behind > the scenes to accelerate this sort of selection. > > Can you provide me with any further hints? Is your 8 line script able to > select upwards of 100,000 faces within an arbitrary angle tolerance in > under a second or should I adjust my expectations? > > -- You received this message because you are subscribed to the Google Groups "Python Programming for Autodesk Maya" group. To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_maya+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/f99a3196-42d0-4287-b7ac-6355a13bebce%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.