I have modeled fabric and i need to replace polygon tubes with NURBS curves.
The smallest peace left, model in general right.

I can imagine how to build a script if i were able to select each closed edge loop of tube: find world coordinates of loop and add CV, so at the and i will get the curve in the center of a tube. But i have no idea how to find these loops, especially in right order.
Any thoughts about this task?