# Get center point of a edge loop selection

posted 1084 days ago | 5 comments

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

Thanks

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

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

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

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

posted 1084 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 + boundingBoxMin)/2, (boundingBoxMax + boundingBoxMin)/2, (boundingBoxMax + boundingBoxMin)/2 ]
``````
posted 1084 days ago

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