Get center point of a edge loop selection

by denilson020898 posted 115 days ago | 5 comments

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


by jromero posted 109 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')

        yVertex = edge.getPoint(0, space='world')

        zVertex = edge.getPoint(0, space='world')

    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))

by Orkah posted 115 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.

hope this helps. cheers

by vshotarov posted 115 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(,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 115 days ago

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