Iterating over edge loops or (even better) groups of vertices to rebuild cylindrical geometry


I am trying to rebuild the following mesh pipe to an extruded curve object (actually lots of them, that’s why I am looking for a scripting approach). I’ve attached the object to this post.

The topology isn’t straightforward, there are some broken edgeloops and it also has an interior (thickness) to it. My current approach is to select edge loops / complete circles, collapse them to a single vert and then convert the resulting poly line to a curve. It seems to work perfectly but I am wondering how to translate this to a script with the least amount of user input. Specifically I am having trouble dealing with edge loops: Checking if the selected vertices are actually a contigous loop. Also how to iterate over edge loops and/or “batches” of vertices: Multiple vertex selections that are connected but not still in seperate groups (if that makes sense, think several edge loops but they don’t have to be loops).

If anyone can help me with these topics OR has a different idea or apporach to rebuild this geometry it would be much appreciated.

Thanks!pipe_example.obj (62.0 KB)