Untitled

mail@pastecode.io avatar
unknown
plain_text
a month ago
1.5 kB
2
Indexable
Never
import bpy

class VertexCursorOperator(bpy.types.Operator):
    bl_idname = "view3d.vertex_cursor_operator"
    bl_label = "Move Cursor to Next Vertex"
    
    _current_vertex_index: int = 0

    def execute(self, context):
        obj = context.active_object
        if obj and obj.type == 'MESH':
            vertices = obj.data.vertices
            if self._current_vertex_index < len(vertices):
                co = vertices[self._current_vertex_index].co
                context.scene.cursor.location = obj.matrix_world @ co
                self._current_vertex_index += 1
                if self._current_vertex_index >= len(vertices):
                    self._current_vertex_index = 0  # Reset index to start over
            else:
                self._current_vertex_index = 0  # Reset index if out of range
        return {'FINISHED'}

class VertexCursorPanel(bpy.types.Panel):
    bl_label = "Vertex Cursor Panel"
    bl_idname = "VIEW3D_PT_vertex_cursor_panel"
    bl_space_type = 'VIEW_3D'
    bl_region_type = 'UI'
    bl_category = 'Tool'
    
    def draw(self, context):
        layout = self.layout
        layout.operator("view3d.vertex_cursor_operator")

def register():
    bpy.utils.register_class(VertexCursorOperator)
    bpy.utils.register_class(VertexCursorPanel)

def unregister():
    bpy.utils.unregister_class(VertexCursorOperator)
    bpy.utils.unregister_class(VertexCursorPanel)

if __name__ == "__main__":
    register()
Leave a Comment