Rotate Surface UV to certain directions through Rhino Common

Hi,

Got a question about UV mapping rotation through Rhino Common:

How could I change the UV orientation of a surface to make it align with its geometrical shape? I found a pretty neat method here but unfortunately it works only for planar surface.

In my test case, it is a non-planar surface that wraps in a way like below; It has one direction that has clean cuts, but irregular ends on the other direction. The goal is to set the UV as the side that has clean cuts indicates.

My initial rough thoughts:

Untrim from the crooked edges to get clean cuts → Boundingbox the original → Intersect the untrimed with the bbox → sweep 2 to get uv reoriented → use the original crooked edges to trim it back to original shape.

But I wonder if there are better ways, any other thoughts? Thank you!

uv_rotation.3dm (2.3 MB)