Hi Aren, if I understood right, what you want to do is:
from your object, delete all the faces that have negative X position in
relation to the world?
if so, i believe you are doing a bit more work then necessary. This code
below is working and it will delete faces on the negative X side of the
world
also, normally you don't want to select things with the command line unless
you absolutely need to.
Will over comment it just in case...
##============================
import maya.cmds as cmds
# get the selection of the object - you can do some error checking, if not
polygon or if component selection...
sel = cmds.ls(sl=1)
# get the amount of faces
faceCount = cmds.polyEvaluate(sel[0], face=1)
# array variable to hold negative faces later on
negativeFaces = []
# loop for each face...
for i in range(faceCount):
# check if the X position of that face is negative with xform
command, note that [0] is the X value [1] for y, [2] for z
if cmds.xform(sel[0]+'.f[%d]'%i, q=1, ws=1, t=1)[0] < 0:
# if so add to list
negativeFaces.append(sel[0]+'.f[%d]'%i) # the empty list will hold
all the faces in the negative X side after the loop is done
# delete all faces in negative side
cmds.delete(negativeFaces)
# clean the history
cmds.delete(sel[0], ch=1)
##=====================================================
hope this helps.
cheers.
On Monday, January 27, 2014 4:13:31 PM UTC-2, Aren Voorhees wrote:
>
> 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/1cdd5715-cc8a-4795-aa3e-405ed50eb407%40googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.