2
$\begingroup$

I have written a small script to bevel selected edges and want to be able to select the newly created faces in bmesh. It returns a dictionary of the faces, edges, and verts with the types in long-form with no way that I understand to extract the index from it. Here is the code:

import bpy
import bmesh
from bpy import context

bpy.ops.object.mode_set(mode='OBJECT')

obj = context.active_object.data
bm =bmesh.new()
bm.from_mesh(obj)

selected_edge = [e for e in bm.edges if e.select]


ret = bmesh.ops.bevel(bm, 
                      geom=selected_edge, 
                      offset=0.3,
                      segments=6,
                      affect='EDGES',
                      profile=0.5, 
                      material=-1)


x = ret.get("faces")
print(x)

for k,v in ret.items():
    print(k)
    for e in v:
        print(e)


bm.to_mesh(obj)
obj.update()
bm.free()

The data returned looks like this:

[<BMFace(0x000001FD6F841BE0), index=5, totverts=4>, <BMFace(0x000001FD6F841C18), index=6, totverts=4>, <BMFace(0x000001FD6F841C50), index=7, totverts=4>, <BMFace(0x000001FD6F841C88), index=8, totverts=4>, <BMFace(0x000001FD6F841CC0), index=9, totverts=4>, <BMFace(0x000001FD6F841CF8), index=10, totverts=4>]
faces
<BMFace(0x000001FD6F841BE0), index=5, totverts=4>
<BMFace(0x000001FD6F841C18), index=6, totverts=4>
<BMFace(0x000001FD6F841C50), index=7, totverts=4>
<BMFace(0x000001FD6F841C88), index=8, totverts=4>
<BMFace(0x000001FD6F841CC0), index=9, totverts=4>
<BMFace(0x000001FD6F841CF8), index=10, totverts=4>
edges
<BMEdge(0x000001FD701D3DD0), index=7, verts=(0x000001FD7020FD88/15, 0x000001FD7020FD18/13)>
<BMEdge(0x000001FD701D3E20), index=8, verts=(0x000001FD7020FD18/13, 0x000001FD7020FBC8/7)>
<BMEdge(0x000001FD701D3E70), index=9, verts=(0x000001FD7020FBC8/7, 0x000001FD7020FCE0/12)>
<BMEdge(0x000001FD701D3EC0), index=10, verts=(0x000001FD7020FCE0/12, 0x000001FD7020FD88/15)>
<BMEdge(0x000001FD701D3F10), index=11, verts=(0x000001FD7020FDC0/16, 0x000001FD7020FD88/15)>
<BMEdge(0x000001FD701D3F60), index=12, verts=(0x000001FD7020FCE0/12, 0x000001FD7020FCA8/11)>
<BMEdge(0x000001FD701D3FB0), index=13, verts=(0x000001FD7020FCA8/11, 0x000001FD7020FDC0/16)>
<BMEdge(0x000001FD701D4000), index=14, verts=(0x000001FD7020FDF8/17, 0x000001FD7020FDC0/16)>
<BMEdge(0x000001FD701D4050), index=15, verts=(0x000001FD7020FCA8/11, 0x000001FD7020FC70/10)>
<BMEdge(0x000001FD701D40A0), index=16, verts=(0x000001FD7020FC70/10, 0x000001FD7020FDF8/17)>
<BMEdge(0x000001FD701D40F0), index=17, verts=(0x000001FD7020FE30/18, 0x000001FD7020FDF8/17)>
<BMEdge(0x000001FD701D4140), index=18, verts=(0x000001FD7020FC70/10, 0x000001FD7020FC38/9)>
<BMEdge(0x000001FD701D4190), index=19, verts=(0x000001FD7020FC38/9, 0x000001FD7020FE30/18)>
<BMEdge(0x000001FD701D41E0), index=20, verts=(0x000001FD7020FE68/19, 0x000001FD7020FE30/18)>
<BMEdge(0x000001FD701D4230), index=21, verts=(0x000001FD7020FC38/9, 0x000001FD7020FC00/8)>
<BMEdge(0x000001FD701D4280), index=22, verts=(0x000001FD7020FC00/8, 0x000001FD7020FE68/19)>
<BMEdge(0x000001FD701D42D0), index=23, verts=(0x000001FD7020FD50/14, 0x000001FD7020FE68/19)>
<BMEdge(0x000001FD701D4320), index=24, verts=(0x000001FD7020FC00/8, 0x000001FD7020FB90/6)>
<BMEdge(0x000001FD701D4370), index=25, verts=(0x000001FD7020FB90/6, 0x000001FD7020FD50/14)>
verts
<BMVert(0x000001FD7020FB90), index=6>
<BMVert(0x000001FD7020FBC8), index=7>
<BMVert(0x000001FD7020FC00), index=8>
<BMVert(0x000001FD7020FC38), index=9>
<BMVert(0x000001FD7020FC70), index=10>
<BMVert(0x000001FD7020FCA8), index=11>
<BMVert(0x000001FD7020FCE0), index=12>
<BMVert(0x000001FD7020FD18), index=13>
<BMVert(0x000001FD7020FD50), index=14>
<BMVert(0x000001FD7020FD88), index=15>
<BMVert(0x000001FD7020FDC0), index=16>
<BMVert(0x000001FD7020FDF8), index=17>
<BMVert(0x000001FD7020FE30), index=18>
<BMVert(0x000001FD7020FE68), index=19>

I want to know how I can extract the indexes of the faces from this data. Any help would be appreciated.

$\endgroup$

1 Answer 1

1
$\begingroup$

The return data is in the form of a Python dictionary. If you want just the list of indices of faces, this code will do it:

for face in ret['faces']: print(face.index)

The items in the dictionary are bmesh.types.BMFace items and you can read the details of their members on the BMFace part of the manual.

$\endgroup$
2
  • 2
    $\begingroup$ Thanks! I was making it harder than it needed to be! I need to go over the classes in bmesh.types and what attributes and methods are available. $\endgroup$ Commented Feb 25, 2022 at 17:20
  • 1
    $\begingroup$ you're welcome. $\endgroup$ Commented Feb 25, 2022 at 17:51

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .