Getting the Selected Faces.

I know in the documentation you can get the selected faces of an NMesh with getSelectedFaces() or use the NFace method to do so…but that only seems to work for the faces selected via face select mode.

Since the 2.35 is able to select faces via Edit Mode, is there a way to get those faces selected there?

I thought about just going through each face and if all the verts were selected for that face, then that would do it, except that that’s is not necessarily true. You could select the bottom face and the top face of a cube and through that method, all of the faces would be selected.

You can use this part of code from one of my scripts:


import Blender
from Blender import Scene, Object, NMesh, Window

#########################################
def D_Faces_f_VertAndD_Edges_f_Face(me):#
#########################################
# Dicos sous forme de NMesh.verts #
###################################

	D_ffv = {} ### DicoFacesfromVert={[NMVert]: [[NMFace],[NMFace],[NMFace]],  [NMVert]: [[NMFace],[NMFace]],  [NMVert]:  ...}
	D_eff = {} ### DicoEdgesfromFace={[NMFace]: [[NMVert,NMVert], [NMVert,NMVert],[NMVert,NMVert],[NMVert,NMVert]],  [NMFace]: [[NMVert,NMVert], [NMVert, ...}


	for x in me.verts:
		D_ffv[x] = []

	MeshFaces = me.faces

	for f in MeshFaces:
		lenF = len(f)

		D_eff[f] = []

		if lenF == 2:
			D_eff[f] = [f.v]

		else:

			for vidx in range(lenF):

				###### Section L_Ffv ##########
				if f not in D_ffv[f.v[vidx]]:
					D_ffv[f.v[vidx]].append(f)

				###### Section D_eff #########
				if vidx < (lenF-1):
					D_eff[f].append([f.v[vidx], f.v[vidx+1]])
				else:
					D_eff[f].append([f.v[vidx], f.v[0]])


	return D_ffv, D_eff

#######################
#### Fonction reduce ##
def reduce(list):     #
#######################

	list.sort()
	list.reverse()

	lenlist = len(list) - 1
	if lenlist > 0:
		compt = 0

		while compt < lenlist:

			if list[compt] == list[compt + 1]:
				list.remove(list[compt])
				lenlist -= 1

			else:
				compt += 1

	list.reverse()

	return list

##############################
def getSelFacesFromSelVerts(me):
##############################
	global D_FacesfromVert, D_EdgesfromFace

	#####################################
	#####################################
#	print "Building ... DicoFacesfromVert"
	D_FacesfromVert, D_EdgesfromFace = D_Faces_f_VertAndD_Edges_f_Face(me)
#	print "DicoFacesfromVert...OK"
	#####################################

	L_SelV = [] #### Liste des vertex selectionnes ####
	for v in me.verts:
		if v.sel:
			L_SelV.append(v)
		v.sel = 0

	LF = []

	[LF.extend(D_FacesfromVert[vtc]) for vtc in L_SelV]
	reduce(LF)


	NewL_SelV = [] #### La nouvelle liste de vertex sur lequel nous allons travailler ####
	NewLF = [] #### La nouvelle liste de faces #####
	for f in LF:
		chk = []
		[chk.append(v) for v in f.v if v in L_SelV]
		if len(chk) == len(f.v):
			NewL_SelV.extend(f.v)
			NewLF.append(f)

	for v in NewL_SelV:
		v.sel = 1
	for f in me.faces:
		f.flag = 0
		if f in NewLF:
			f.flag = 1

	return NewLF


##############################
obj = Object.GetSelected()[0]
mesh = obj.data

LSF = getSelFacesFromSelVerts(mesh) #### Return list of "NMFace" from selected vertex ####

print LSF

++
ph

awesome. I will give it a try. Thanks.