Get center point of a edge loop selection

by denilson020898 posted 40 days ago | 5 comments

How to get a center point of the selected edge loop ?

Thanks

by jromero posted 34 days ago

Hi Denilson, reading a bit in PyMel, I found this solution with MeshEdge getPoint

import pymel.core as pm

def locatorMedian():
    """
    given an edge(s) selection, creates a locator in the median position

    """
    x_pos_list = []; y_pos_list = []; z_pos_list = []
    oSel = pm.selected(flatten=True)


    for edge in oSel:
        xVertex = edge.getPoint(0, space='world')
        x_pos_list.append(xVertex[0])

        yVertex = edge.getPoint(0, space='world')
        y_pos_list.append(xVertex[1])

        zVertex = edge.getPoint(0, space='world')
        z_pos_list.append(xVertex[2])


    xPos = sum(x_pos_list)/len(x_pos_list)
    yPos = sum(y_pos_list)/len(y_pos_list)
    zPos = sum(z_pos_list)/len(z_pos_list)

    pm.spaceLocator(p=(xPos, yPos, zPos))


locatorMedian()
by Orkah posted 40 days ago

hi denilson,

I found a quick way to find what you are asking for, the only problem is that you have to select edge loops before running the code.

https://paste2.org/51B10sxC

hope this helps. cheers

by vshotarov posted 40 days ago

Oh, that's a really clever way to do it! I wouldn't have thought to take it from the manipulator.

Here's what I've been doing.

import maya.cmds as mc

boundingBox = mc.exactWorldBoundingBox(mc.ls(sl=1,fl=1))
boundingBoxMin = boundingBox[:3]
boundingBoxMax = boundingBox[-3:]
centre = [(boundingBoxMax[0] + boundingBoxMin[0])/2, (boundingBoxMax[1] + boundingBoxMin[1])/2, (boundingBoxMax[2] + boundingBoxMin[2])/2 ]
by denilson020898 posted 40 days ago

thanks, i will give it a shot. didn't know that I could retrieve the manipulator's position.