Eyerig/Grow vertex selection along the correct edge loop direction

Hi everyone, I’m trying to automate the creation of a facial rig.
For the eye, I followed this great tutorial: https://www.youtube.com/watch?v=-rtys3vFmso&t=30s.

I’ve finished writing the code for the structure, and now I’d like to apply clean weighting to the area around the eye.

Since in this rig each vertex along the eye’s edge loop has its own joint, my plan is as follows:

  1. Identify the vertex associated with each joint (fig.01)

    Fig.01

  2. For each identified vertex, expand the selection by a given number of vertices and create an ordered list of vertices for each branch (fig.02)

    Fig.02

  3. Once all branches have been defined, apply the vertex weights for each branch in an orderly manner. For example:

branch_01 = (vtx[0], vtx[1], vtx[2], vtx[3], vtx[4], vtx[5])

vtx[0] = [(“eye_joint”, 1.0), (“main_joint”, 0.0)] # first vertex weight
vtx[1] = [(“eye_joint”, 0.8), (“main_joint”, 0.2)] # second vertex weight
vtx[2] = [(“eye_joint”, 0.6), (“main_joint”, 0.4)] # third vertex weight
vtx[3] = [(“eye_joint”, 0.4), (“main_joint”, 0.6)] # fourth vertex weight
vtx[4] = [(“eye_joint”, 0.2), (“main_joint”, 0.8)] # fifth vertex weight
vtx[5] = [(“eye_joint”, 0.0), (“main_joint”, 1.0)] # sixth vertex weight

or driven by a formula that automatically assigns the weights (fig.03).

Fig.03

(For clarity, I haven’t labeled all the vertices in the pictures)

Of course, this is just the approach that came to mind based on my experience. I’m not sure if there are simpler or more efficient methods, so I’d really appreciate hearing other perspectives.

However, if I proceed with this approach, my issue lies in step 2.

After identifying the first vertex, how can I ensure that the selection of subsequent vertices follows the correct direction along the intended edge loop?

I’ve tried several solutions, but none of them have proven to be truly reliable. Does anyone have suggestions or alternative approaches?

(I hope I’ve made myself clear, and I apologize if this was too long.)

So this may be useful to try understanding. The way I solve that problem seems very useful for your issue:
https://www.tech-artists.org/t/get-vertices-of-an-edge-loop-and-sort-them-around-their-unit-circle/14649/2

So here’s one way I’d approach this. It could ABSOLUTELY be optimized, but it’s a start.

First you need to know which way is “out” from your verts. Luckily, the vertices of a face in Maya are always counter-clockwise. So if you know the order of your joint verts, and you know the winding order of a face, you can figure out if a face is outside or inside your vertex loop.
So convert your vertex selection to a face selection, then for each face get its verts in-order, and figure out if that face is outside your ring.

Repeat that process to get all the rings in order.

Then, for every vert in your rings, grow a selection from it, and figure out which vert is in the next ring out.