Edge to faces conversion

Hey everyone!! (new to the forum :slight_smile: )

I’m kind of new to Blender but not to 3D. I’m (or was??, haha) a Maya user.

I’d like to ask for some help: How can I convert an Edge selection to its Faces using Python. I’ve been looking for it in Blender’s docs and in this forum but can’t find it.

In Maya it is polyListComponentConversion (selfexplanatory I think) if you know Maya.

Thanks in advance!!

hi and welcome, I guess you could simply change context, in edit mode, from edge to face…
bpy.context.tool_settings.mesh_select_mode = [False, False, True]

anyway most of mesh operators will let you choose to target vertex, edge or face

I think what needs Xian is one edge, getting the neighboring polygons.
There is an option in Maya and XSI that returns this value by specifying the edge only to be evaluated.
I did something that worked, but only with quads.

hi there oscurart, isn’t that just as expanding the selection and going face mode… it won’t work on n-gons but I think it is fine with tris and quads… or maybe I still don’t get it :expressionless:

import bpy
bpy.ops.object.mode_set(mode='EDIT')
bpy.ops.mesh.select_more()
bpy.context.tool_settings.mesh_select_mode = [False, False, True]

edit: just realized you may need all sorrounding faces, even if they share only one vertex
in that case try something like this


import bpy
vlist = []
flist = []
data = bpy.context.object.data
modo = bpy.context.object.mode
vef = list(bpy.context.tool_settings.mesh_select_mode)
bpy.ops.object.mode_set()

for v in data.vertices:
    if v.select:
        vlist.append(v.index)
        v.select = False
for f in data.faces:
    for w in f.vertices:
        if w in vlist:
            flist.append(f.index)
            break

bpy.ops.object.editmode_toggle()
bpy.context.tool_settings.mesh_select_mode = [False, False, True]
bpy.ops.object.editmode_toggle()

for x in flist: 
    data.faces[x].select = True

bpy.ops.object.editmode_toggle()
bpy.context.tool_settings.mesh_select_mode = vef
bpy.ops.object.mode_set(mode = modo)

Your script if going to edit mode only ‘shows’ all is not ‘orange’ , looks like nothing is selected (though the visualizer show the correct faces selected!)

==>
To see what your script is supposed to do, some small changes are needed. (print can be removed)


import bpy
vlist = []
flist = []
data = bpy.context.object.data
modo = bpy.context.object.mode
print("modo = ", modo)
bpy.ops.object.mode_set()
for v in data.vertices:
    if v.select:
        vlist.append(v.index)
        v.select = False
bpy.ops.object.editmode_toggle()
bpy.ops.object.editmode_toggle()        
for f in data.faces:
    for w in f.vertices:
        if w in vlist:
            flist.append(f.index)
            break
bpy.ops.object.editmode_toggle()
bpy.context.tool_settings.mesh_select_mode = [False,False, True]
bpy.ops.object.editmode_toggle()

print("========flist =",flist)
for x in flist: 
    data.faces[x].select = True
bpy.ops.object.mode_set(mode = 'EDIT')

And if you enable the “Index Visualizer” for only selected faces, you see both do the same!

the script still seems to run ok here, it returns to previous object mode and mesh selection context, but you removed that part…! sure it can be improved, anyway it is far more complex than a single line in maya :wink:

edit: simple gui in properties panel added


import bpy

class PANEL(bpy.types.Panel):
    bl_label = "Extender"
    bl_space_type = "VIEW_3D"
    bl_region_type = "UI"
    def draw(self, context):
        layout = self.layout
        layout.operator("boton.extender")

class BOTON(bpy.types.Operator):
    bl_idname = "boton.extender"
    bl_label = "Extender"
    
    def execute(self, context):
        vlist = []
        flist = []
        data = bpy.context.object.data
        modo = bpy.context.object.mode
        vef = list(bpy.context.tool_settings.mesh_select_mode)
        bpy.ops.object.mode_set()

        for v in data.vertices:
            if v.select:
                vlist.append(v.index)
                v.select = False
        for f in data.faces:
            for w in f.vertices:
                if w in vlist:
                    flist.append(f.index)
                    break

        bpy.ops.object.editmode_toggle()
        bpy.context.tool_settings.mesh_select_mode = [False, False, True]
        bpy.ops.object.editmode_toggle()

        for x in flist: 
            data.faces[x].select = True

        bpy.ops.object.editmode_toggle()
        bpy.context.tool_settings.mesh_select_mode = vef
        bpy.ops.object.mode_set(mode = modo)

        return{'FINISHED'}

def register():
    bpy.utils.register_class(PANEL)
    bpy.utils.register_class(BOTON)

def unregister():
    bpy.utils.unregister_class(PANEL)
    bpy.utils.unregister_class(BOTON)

if __name__ == "__main__":
    register()

Liero, you’re amazing!
The operator “ops.expand” gave no results in trids.
The addon that did this very well, but not exactly what we want.

Exactly what we need is only
select the two sides near the edge.

I made an image.


Thanks a bunch!

ouch you’re right with tris not working with select_more…
so modified the second script to work as you want, it’s not that fast though
abrazo!


import bpy

class PANEL(bpy.types.Panel):
    bl_label = "Extender"
    bl_space_type = "VIEW_3D"
    bl_region_type = "UI"
    def draw(self, context):
        layout = self.layout
        layout.operator("boton.extender")

class BOTON(bpy.types.Operator):
    bl_idname = "boton.extender"
    bl_label = "Extender"
    
    def execute(self, context):
        vlist = []
        flist = []
        data = bpy.context.object.data
        modo = bpy.context.object.mode
        vef = list(bpy.context.tool_settings.mesh_select_mode)
        bpy.ops.object.mode_set()

        for v in data.vertices:
            if v.select:
                vlist.append(v.index)
                v.select = False
        for f in data.faces:
            c = 0
            for w in f.vertices:
                if w in vlist:
                    c += 1
            if c >1 : flist.append(f.index)

        bpy.ops.object.editmode_toggle()
        bpy.context.tool_settings.mesh_select_mode = [False, False, True]
        bpy.ops.object.editmode_toggle()

        for x in flist: 
            data.faces[x].select = True

        bpy.ops.object.editmode_toggle()
        bpy.context.tool_settings.mesh_select_mode = vef
        bpy.ops.object.mode_set(mode = modo)

        return{'FINISHED'}

def register():
    bpy.utils.register_class(PANEL)
    bpy.utils.register_class(BOTON)

def unregister():
    bpy.utils.unregister_class(PANEL)
    bpy.utils.unregister_class(BOTON)

if __name__ == "__main__":
    register()

Simply amazing!
It works fantastically.

I watch as you did and still do not understand. I will study it more.

After contact would be good to have you on msn.

Abrazo loco!
Mil gracias!

Wow, lots of stuff going on here. Thanks a lot, I’m reading it all :slight_smile:

The main part are the three for-loops.
The first looks for all vertices which are included in (your! or actual) selection! and are at once deselected.

The second counts for each face which vertex-indices where selected and remembers those, which have at least
two (earlier) selected vertices ( c > 1 )

The third now selects the relevant faces (in fact their vertices)

The rest is ‘remember’ settings and ‘reset’ them and commands to let Blender see the change and setting ‘face’ mode correct for in between (the [False,False,True]).

But you are right it needs ‘know how’ :wink: