I've found a script that I want to test and use from a thread around, which was marked as "SOLVED" with this script. However, I can't get how this script is used:

import bpy
import bmesh

class SimpleOperator(bpy.types.Operator):
    bl_idname = "object.simple_operator"
    bl_label = "Simple Object Operator"

    def poll(cls, context):
        return (context.object is not None and
            context.object.type == 'MESH' and

    def invoke(self, context, event):
        me = context.object.data
        bm = bmesh.from_edit_mesh(me)
        verts_sel = [v.select for v in bm.verts]
        edges_sel = [e.select for e in bm.edges]
        faces_sel = [f.select for f in bm.faces]

        loc = event.mouse_region_x, event.mouse_region_y
            geom = bm.select_history[-1]
        except IndexError:
            geom = None

        ret = bpy.ops.view3d.select(extend=True, location=loc)
        if ret == {'PASS_THROUGH'}:
            self.report({'INFO'}, "no close-by geom")
            return {'CANCELLED'}

            geom2 = bm.select_history[-1]
            print("geom2 sel 1st", geom2.select)
        except IndexError:
            geom2 = None

        if geom is None:
            geom = geom2

        if isinstance(geom, bmesh.types.BMVert):
            geom_sel = verts_sel
            bm_geom = bm.verts
        elif isinstance(geom, bmesh.types.BMEdge):
            geom_sel = edges_sel
            bm_geom = bm.edges
        elif isinstance(geom, bmesh.types.BMFace):
            geom_sel = faces_sel
            bm_geom = bm.faces

        for sel, g in zip(geom_sel, bm_geom):
            if sel != g.select:

        self.report({'INFO'}, repr(geom))
        return {'FINISHED'}

def register():

def unregister():

if __name__ == "__main__":

The thread I am mention is here: Get Edge / Vertex / Face from mouse position Please, if you can explain what I have to do with this code.



1 Answer 1


Well, basically if you don't define an interface for your operator, you can run your code and then press the Spacebar and search it with the name of "simple object operator" in the box that appears. When you find it, simply click it and it will run. enter image description here

  • $\begingroup$ Hello, I've tried this, 'Spacebar' on the context next to the script editor, however the operator is not present there. $\endgroup$ Commented May 23, 2017 at 11:00
  • $\begingroup$ Probably because the poll function doesn't show that to you. In fact, this function explains where are the conditions for the operator to be applicable . If you remove that part, the operator will be always applicable. I will update my answer with a screenshot anyway. $\endgroup$
    – Rexam
    Commented May 23, 2017 at 11:16
  • $\begingroup$ Your poll function is saying: "You can apply this operator if context.object is not None, if your object is a mesh and if you are in edit mode". In the image I uploaded I just removed this function, but it works perfectly even with that. $\endgroup$
    – Rexam
    Commented May 23, 2017 at 11:26

You must log in to answer this question.

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