Delete all faces that less than zero by x coordinate.


#1

I need to delete half of model using python. As far as I understand I can’t get absolute vertex position to filter it’s position using cmds module, because it always returning coordinates of the pivot point of selected object.

So I ended up using OpenMaya 2.0, and I get filtered MPoints (vertices) using following approach:

selection = OM.MGlobal.getActiveSelectionList()
if (selection.isEmpty):
    fnMesh = OM.MFnMesh(selection.getDagPath(0))
    vertices = fnMesh.getPoints(space=OM.MSpace.kObject)
    mVertices = OM.MPointArray()
    for vertex in vertices:
        if vertex.x > 0:
            mVertices.append(vertex)

but, to be able select those vertices I need somehow covert them to MDagPath and after spending some time on documentation I didn’t find method than can be used to achieve that.

What am I missing?


#2

You could first use MFnMesh.getVertices() to get the faces vertex ids. Then grab the vertex positions in world space and iter through and delete the face if all of the face vertices are less than zero in x.


#3

you can get the vertex position in world space using maya.cmds, but it would be slow since it would require selecting each vertex and querying the position of the manipulator.


#4

have a look at http://ewertb.soundlinker.com/api/api.025.php. With the help of mesh DagPath and MFnSingleIndexedComponent, you create MSelectionList that contains vertex selection. You then set that selection list as active and voila.


#5

Would this work for you?

cmds.polySphere()
 cmds.polySelectConstraint(m=3, t=0x0008, d=3, dp=(5000, 0, 0), da=(1,0,0), db=(0, 5000))
 cmds.delete()

#6

:surprised

you can use xform on components…


#7

So you have a couple of answers already, but just for interest I thought I’d show how I would have done it without OpenMaya.

# assume I have a mesh called pSphere1
import maya.cmds as cmds
mesh = 'pSphere1'
posList = cmds.xform(mesh + '.vtx[li]', q=True, ws=True, t=True)
[/li]posArray = zip(posList[0::3], posList[1::3], posList[2::3])
verts = [mesh+'.vtx[%i]'%id for id, val in enumerate(posArray) if val[0] < 0.0]
faces = cmds.polyListComponentConversion(verts, fv=True, tf=True, internal=True)
cmds.delete(faces)

David