So I have seen some forum postings on past blender releases indicating how to obtain face object/mesh face indexing data, but unfortunately this doesn't work in the present release version of Blender 2.71. At least if you thought you could use.
obj = bpy.context.active_object
and then,
obj.data.faces
obj.data
does not contain a module obj.data.faces (at least not in the present blender release).
If you were wondering why in the world you might want to do this...well there is a context that I have need of here. Namely, to parse select and structure vertex group data based upon selected face data. I want to subdivide selected faces into separate vertex groups in a procedural batch automated way (without having to manually grab each selected face and then having set up separate faces and then manually toggling add new vertex groups). Thus I spent sometime checking completions on obj.data roots to find nothing really (I investigated the polys module, but this appears to be a big dead end), but I did manage to find a work around method this way:
import bpy
import bmesh
bm = bmesh.new() # create an empty BMesh
bm.from_mesh(obj) # fill it in from a Mesh
# Modify the BMesh, can do anything here...
for v in bm.verts:
v.co.x += 1.0
count = 0
faces = bm.faces
for face in faces:
if face.select:
count += 1
#an example of getting the index of the vertex in a face
faces[0].verts[0].index
obj = bpy.context.active_object
and then,
obj.data.faces
obj.data
does not contain a module obj.data.faces (at least not in the present blender release).
If you were wondering why in the world you might want to do this...well there is a context that I have need of here. Namely, to parse select and structure vertex group data based upon selected face data. I want to subdivide selected faces into separate vertex groups in a procedural batch automated way (without having to manually grab each selected face and then having set up separate faces and then manually toggling add new vertex groups). Thus I spent sometime checking completions on obj.data roots to find nothing really (I investigated the polys module, but this appears to be a big dead end), but I did manage to find a work around method this way:
import bpy
import bmesh
bm = bmesh.new() # create an empty BMesh
bm.from_mesh(obj) # fill it in from a Mesh
# Modify the BMesh, can do anything here...
for v in bm.verts:
v.co.x += 1.0
count = 0
faces = bm.faces
for face in faces:
if face.select:
count += 1
#an example of getting the index of the vertex in a face
faces[0].verts[0].index
So above we can test a face to see if its active, and then we can select from this face a vertex to find its indexing position. With this we should be able to go back and assign vertex group without making this too painfully slow (especially nice if you are working with larger scale data sets).
face.select is a boolean value that tells us whether or not the face is selected or not, and is necessary in this algorithms planned design.
No comments:
Post a Comment