Thanks Jesse! 

I also found a way with the polyInfo command which can return values for the 
face normal itself, but my code is quite a bit longer to get the same result as 
you did with the verts. Thought I'd post it anyways. I'm assuming with these 
values of 0 to 1 or 0 to -1 for x,y,z that I should now turn that data into an 
angle in world space? I think that's what the next step is anyways.

import maya.cmds as cmds
import decimal
decimal.getcontext().prec = 2
def reFunction(item, isolate):
        s = re.compile( isolate )
        f = s.finditer(item)
        return [ x.span() for x in f ]
sl = cmds.ls(selection=True, flatten=True)
faceList = []
for i in sl:
        x = cmds.polyInfo( i, fn=True )
        faceList.append(x)
xValue  = []
yValue  = []
zValue  = []
for i in range(len(faceList)):
        y = reFunction(faceList[i][0], ': ') # finding the split in the poly 
face normal info
        a = faceList[i][0][(y[0][1]):] # removes all text and leaves values
        p = reFunction(a, '\s+') # finds the whitespace between x,y,z values
        xValue.append( decimal.Decimal( a[:p[0][0] ] ) )
        yValue.append( decimal.Decimal( a[ p[0][1] : p[1][0] ] ) )
        zValue.append( decimal.Decimal( a[ p[1][1]: ] ) )
xAverage = float( decimal.Decimal (sum(xValue) ) / 
decimal.Decimal(str(float(len(xValue)))) )
yAverage = float( decimal.Decimal (sum(yValue) ) / 
decimal.Decimal(str(float(len(yValue)))) )
zAverage = float( decimal.Decimal (sum(zValue) ) / 
decimal.Decimal(str(float(len(zValue)))) )
print xAverage
print yAverage
print zAverage


Cheers,

J


On Friday, January 25, 2013 11:28:35 PM UTC+1, Jesse Capper wrote:
> Typo at the start:
> You can get vertexFace normal directions from the polyNormalPerVertex command.
> 
> On Friday, January 25, 2013 2:26:39 PM UTC-8, Jesse Capper wrote:
> > You can vertexFace normals from the polyNormalPerVertex command.
> > 
> > So something like:
> > 
> > # Get the face vertices from the face
> > vtxfaces = cmds.polyListComponentConversion(my_poly_face, ff=True, tvf=True)
> > # Get a flattened list of the normals (the length of this list is: number 
> > of vertexFaces * 3[for the x,y,z coord of each normal])
> > flatnormals = cmds.polyNormalPerVertex(vtxfaces, q=True, xyz=True)
> > # Which you can group into x,y,z 3-tuples if you want:
> > normals = []
> > for i in range(0, len(flatnormals), 3):
> >     normals.append(flatnormals[i:i+3])
> > 
> > There's a slicker way of splitting a list into n-sized chunks, but it's not 
> > as obvious/easy to figure out at first glance:
> > normals = zip(*[iter(flatnormals)]*3)
> > 
> > On Friday, January 25, 2013 10:47:34 AM UTC-8, JR wrote:
> > > Hey all,
> > > 
> > > Been learning a lot from this group but there is one problem that I can't 
> > > seem to figure out. I'm trying to calculate the angle of a selected face 
> > > based on the normal but I have no idea how to get that information. 
> > > Nothing in the python command field seems to help. Any ideas?
> > > 
> > > Thanks!
> > > 
> > > J

-- 
You received this message because you are subscribed to the Google Groups 
"Python Programming for Autodesk Maya" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].


Reply via email to