Hey all,

I am trying to create a tool for modeling that will delete all faces that 
are located in negative x (as a modeler, I've always wanted something like 
this).  I've got most of it working - I create a list of the faces, then 
loop through them, determining their position using the positions of their 
verts.  It's the last line, or few lines where I'm a bit lost.  I'm 
appending all faces that come back negative into a list, then trying to 
delete that list.  Clearly, I'm doing something wrong there.

If you notice anything else that could be done better, feel free to let me 
know!  

If anyone can help out a lost beginner, I'd be extremely thankful!

import maya.cmds as cmds


#Define object name

curSel = (cmds.ls (sl=True)[0])


numOfFaces = len(cmds.getAttr(curSel + ".f[:]"))

for i in xrange (0,numOfFaces):

    cmds.select(curSel + ".f[%d]" %i, add=1)


#Create list (array) of faces in current object

faceIndexList = cmds.ls(sl=True,fl=True)

    

#Loop through the list of faces from above

for i in faceIndexList:

    

    #Selects the current face

    cmds.select (i)

    

    #Converts selection to verts (tv == toVerts)

    faceToVerts = cmds.polyListComponentConversion (tv=1)

    cmds.select (faceToVerts)

    

    #Stores the selected verts into a variable (fl == Flatten, which lists 
out things individually)

    vertIndexList = (cmds.ls (sl=True,fl=True))

    

    #Creating empty position variables to later store the vectors of the 
verts in

    posX = 0

    posY = 0

    posZ = 0

    

    #Loops through verts in vertIndexList

    for j in vertIndexList:

        

        cmds.select (j)

        

        #Sets the total number of selected verts (would be 4 in most cases)

        totalVertNum = len(vertIndexList)

        

        #Gets the vector location of each vert

        vertPos = cmds.xform(query=True, translation=True)

        

        #Supposed add the X value of the selected vert to the value from 
the previous itteration (starts at 0) 

        posX += vertPos[0]

        #Supposed add the Y value of the selected vert to the value from 
the previous itteration (starts at 0)         

        posY += vertPos[1]

        #Supposed add the Z value of the selected vert to the value from 
the previous itteration (starts at 0)         

        posZ += vertPos[2]

        

        #Finds the center of the face by creating a vector 

        faceCenter = (posX/totalVertNum), (posY/totalVertNum), (posZ/
totalVertNum)

    

    #Creates empty list to store negative faces in

    negFaces = []

       

    #If the faceCenterer variable is negative

    if faceCenter[0] < 0:

        

        #Appending all the negative x faces into negFaces

        negFaces.append (i)

        

#I thought this would delete all faces that had been appended into 
negFaces, but clearly I thought wrong!

for i in negFaces:

    cmds.delete (i)

    

    






-- 
You received this message because you are subscribed to the Google Groups 
"Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/python_inside_maya/6ede466d-3a29-4e3d-ab39-22e15ae6a862%40googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to