2
$\begingroup$

I found this thread and I already have Developer Extras enabled but I noticed that sometimes some operators don't show up in the F3 menu search despite REGISTER being part of the bl_options and being registered with bpy.utils.register_class(MESH_OT_RemoveLoneVertices). Other operators that get registered in the same file as this one do show up in F3. So why does this one not show up? So it's like some randomly show up and others don't. Do you see anything wrong with this file in particular?

import bpy
import bpy_types
import bmesh

class MESH_OT_RemoveLoneVertices(bpy.types.Operator):
    bl_idname = "mesh.remove_lone_vertices"
    bl_label = "Remove Lone Vertices"
    bl_description = "Remove vertices that are not connected to any edges"
    bl_options = {'REGISTER', 'UNDO'}

    def execute(self, context) -> set[str]:

        obj = bpy.context.active_object
        mesh = obj.data

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

        bm = bmesh.from_edit_mesh(mesh)
        bm.edges.ensure_lookup_table()
        bm.verts.ensure_lookup_table()

        bpy.ops.mesh.select_all(action='DESELECT')

        for vert in bm.verts:
            if not vert.link_edges:
                vert.select = True

        bmesh.update_edit_mesh(mesh)
        bpy.ops.mesh.delete(type='VERT')

    def draw(self, context: bpy_types.Context) -> None:
        pass

    @classmethod
    def poll(cls, _context):
        return False
$\endgroup$

2 Answers 2

2
$\begingroup$

Upon investigation, I identified the root cause of the issue with the test operator. It appears that I neglected to adjust the return value to True within the poll function. This oversight resulted in the poll function consistently returning False. Typically, the poll function evaluates certain conditions to determine the operator's availability. Even if the conditions aren't met, Blender usually displays the operator in the F3 search, albeit grayed out. However, when the poll function consistently returns False, Blender excludes the operator entirely from the search list, rendering it permanently inaccessible.

Update: Upon closer inspection, even if you have a condition to check if an object is active or not, if it is not active, Blender entirely excludes the operator from the list instead of graying it out. This behavior seems inconsistent, as I noticed that some operators, such as those that inherit from bpy_extras.io_utils.ExportHelper, still get displayed but are grayed out when not usable.

@classmethod
    def poll(cls, context):
        return context.active_object is not None and context.active_object in context.selected_objects
$\endgroup$
0
$\begingroup$

There are some problems with your script, it's not correct.

Here is the correct one:

import bpy
from bpy.types import Operator
import bmesh


class MESH_OT_RemoveLoneVertices(Operator):
    bl_idname = "mesh.remove_lone_vertices"
    bl_label = "Remove Lone Vertices"
    bl_description = "Remove vertices that are not connected to any edges"
    bl_options = {'REGISTER', 'UNDO'}

    @classmethod
    def poll(cls, context):
        return True

    def execute(self, context):
        obj = context.active_object
        mesh = obj.data

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

        bm = bmesh.from_edit_mesh(mesh)
        bm.edges.ensure_lookup_table()
        bm.verts.ensure_lookup_table()

        bpy.ops.mesh.select_all(action='DESELECT')

        for vert in bm.verts:
            if not vert.link_edges:
                vert.select = True

        bmesh.update_edit_mesh(mesh)
        bpy.ops.mesh.delete(type='VERT')

        return {"FINISHED"}
    
    
def register():
    bpy.utils.register_class(MESH_OT_RemoveLoneVertices)


def unregister():
    bpy.utils.unregister_class(MESH_OT_RemoveLoneVertices)


if __name__ == "__main__":
    register()
$\endgroup$
1
  • 4
    $\begingroup$ Could you describe what is wrong with the original script. Maybe edit your post and comment what edits you made so it is easier for visitors to leant from your answer $\endgroup$ Commented Apr 27 at 16:39

You must log in to answer this question.

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