You can use xform, but you’ll have to take the rotation pivot into account as well.
I think the snippet below will do what you need.
from maya import cmds, OpenMaya
node = "pSphere1"
vertices = cmds.ls("{}.vtx[*]".format(node), fl=True)
verticesMirrored = []
# get rotation pivot
pivotOffset = cmds.getAttr("{}.rotatePivot".format(node))[0]
pivotOffset = OpenMaya.MVector(*pivotOffset)
# loop vertices
for vtx in vertices:
# query position in local space
pos = cmds.xform(vtx, q=True, os=True, t=True)
pos = OpenMaya.MVector(*pos)
# subtract the rotation pivot from the local space position
pos -= pivotOffset
# check x position is lower than 0
if pos.x < 0:
verticesMirrored.append(vtx)
# select vertices to mirror
cmds.select(verticesMirrored)
If you run this on a sphere you get something like this.
The plane in the picture is where the pivot point is.
Thank you R.Joosten this helps a lot! I’m having trouble converting this to for current selection though.
I don’t get why I can’t make it work for my current selected object?
If i write
node = cmds.ls(sl=True)
I get this error:
Error: Syntax error: unexpected end [ at position 1 while parsing:
[].vtx[]
^
: [].vtx[]
Traceback (most recent call last):
File “”, line 6, in
RuntimeError: Syntax error: unexpected end [ at position 1 while parsing:
[].vtx[]
^
: [].vtx[] #