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)
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/1cdd5715-cc8a-4795-aa3e-405ed50eb407%40googlegroups.com.--
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 python_inside_m...@googlegroups.com.
Do you want to know if the center is positive X or if any part of the face is positive X?
If you just want to know if a face crosses or is in negative x then you could get the boundingBox with polyEvaluate, and check if the minX is negative.
If you want the center, the Maya API can tell you it (is there a commands equiv?)
http://mayastation.typepad.com/files/getfacecenters-1.py
--
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 python_inside_m...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/68190869-e9a1-4f2f-a7e0-0f6cf1ea410a%40googlegroups.com.
import maya.cmds as cmds
#Get current selection
curSel=cmds.ls(sl=1)[0]
#Create list of all faces in object
faceIndex=cmds.polyEvaluate(curSel,face=1)
#Empty list
negativeFaces=[]
#loop through faces
for i in xrange(faceIndex):
curFace = curSel + '.f[%d]' % i
#If the exactWorldBoundingBox is negative in X append that face to the empty list
if cmds.exactWorldBoundingBox (curSel + ".f [%d]" %i)[0] < 0 :
negativeFaces.append(curFace)
#Delete the faces that were put into the empty list
cmds.delete(negativeFaces)
cmds.delete(curSel, ch=1)
One thing I noticed while working on this (which gave me some serious confusion) is that when you create a default sphere, some of the edges/verts that you would think are exactly in the center of the world, actually aren't. So when testing this sort of thing on a sphere, I'd recommend snapping all the center verts to the center of the world first, to avoid getting super annoyed, like me ;)
Ævar, that sounds like that might be a good way of doing this too - I'll definitely give it a try, thanks!
requires maya "2014";
createNode transform -n "mirrorCutPlane1";
setAttr ".r" -type "double3" 0 90 0 ;
setAttr ".smd" 4;
createNode sketchPlane -n "mirrorCutPlane1Shape" -p "mirrorCutPlane1";
setAttr -k off ".v";
createNode transform -n "polySurface1";
createNode mesh -n "polySurfaceShape1" -p "polySurface1";
setAttr -k off ".v";
setAttr -s 2 ".iog[0].og";
setAttr ".vir" yes;
setAttr ".vif" yes;
setAttr ".uvst[0].uvsn" -type "string" "map1";
setAttr ".cuvs" -type "string" "map1";
setAttr ".dcc" -type "string" "Ambient+Diffuse";
setAttr ".covm[0]" 0 1 1;
setAttr ".cdvm[0]" 0 1 1;
setAttr ".vbc" no;
createNode polySphere -n "polySphere1";
createNode polyCut -n "polyCut1";
setAttr ".uopa" yes;
setAttr ".ics" -type "componentList" 1 "f[*]";
setAttr ".ix" -type "matrix" 1 0 0 0 0 1 0 0 0 0 1 0 0 0 0 1;
setAttr ".ws" yes;
setAttr ".mp" -type "matrix" 1 0 0 0 0 1 0 0 0 0 1 0 0 0 0 1;
setAttr ".ps" -type "double2" 2.0000002384185791 2 ;
setAttr ".df" yes;
connectAttr "polyCut1.out" "polySurfaceShape1.i";
connectAttr "polySphere1.out" "polyCut1.ip";
connectAttr "mirrorCutPlane1.t" "polyCut1.pc";
connectAttr "mirrorCutPlane1.r" "polyCut1.ro";--
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 python_inside_m...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/c3f03679-80e6-4ab1-9dc2-6c1ab871e46a%40googlegroups.com.