Maya: Select -X Half of Object using object space pivot orientation in Maya Python?




Forgive me I’m quite new to scripting and this seems really complicated… not sure where to start.

Is it possible to select vertices in the -x direction of an objects current pivot orientation?

I’m trying to use that function in delete half and mirror, delete half and mirror instance scripts

I looked at polyselectscontraints and xform but I don’t think they do what I want…


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 ="{}.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:

# select vertices to mirror

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 =

I get this error:

Error: Syntax error: unexpected end [ at position 1 while parsing:
: [].vtx[
Traceback (most recent call last):
File “”, line 6, in
RuntimeError: Syntax error: unexpected end [ at position 1 while parsing:
: [].vtx[
] #


Is this not because returns a list with the selected objects name in it? So you should just have to add [0] at the end of it.



ah geeze, basic mistake. thanks Boogey