Script is selecting all the objects (unwanted) Although my script works as it should I'm experiencing a odd behaviour when I run it, all the objects get selected and I have no idea why this is happening.
import bpy
import os
import subprocess
import math
from bpy.props import (
    FloatProperty,
    StringProperty,
)
from bpy_extras.io_utils import ImportHelper
from mathutils import Matrix, Vector
from bpy.types import (
    Header,
    Menu,
    Panel,
)
from math import isclose


class SelectByNameOperator(bpy.types.Operator):
    &quot;&quot;&quot;Description&quot;&quot;&quot;
    bl_idname = &quot;object.selected_by_name_operator&quot;
    bl_label = &quot;Select objects by name&quot;
    bl_options = {'REGISTER', 'UNDO'}

    name = StringProperty(
            name=&quot;Object name&quot;,
            )

    def execute(self, context):
        for obj in bpy.context.scene.objects:
            if obj.name.startswith(self.name):
                obj.select_set(True)
                bpy.context.view_layer.objects.active = obj
            else: 
                obj.select_set(False)

                
                
        return {'FINISHED'}                 


class MyPanel(Panel):
    &quot;&quot;&quot;Creates a Panel in the Object properties window&quot;&quot;&quot;
    bl_space_type = 'VIEW_3D'
    bl_region_type = 'UI'
    bl_category = &quot;Test&quot;
    bl_label = &quot;Test&quot;
    bl_idname = &quot;MyPanel&quot;
    
    
    def draw(self, context):
        layout = self.layout
    
        box = layout.box()
        row = box.column()
        row.operator(&quot;object.selected_by_name_operator&quot;)

    
def register():
    bpy.utils.register_class(MyPanel)
    bpy.utils.register_class(SelectByNameOperator)
    
def unregister():
    bpy.utils.unregister_class(MyPanel)
    bpy.utils.unregister_class(SelectByNameOperator)
    
    
if __name__ == &quot;__main__&quot;:
    register()
All strings &quot;start with nothing&quot;.
Simple test in python console
&gt;&gt;&gt; x = &quot;xxx&quot;
&gt;&gt;&gt; x.startswith(&quot;&quot;)
True

Similarly with your operator since the default value when not set of a string property is &quot;&quot;.
Either test for this, or give it some default.
Note, there is already a similar op, to select all objects that start with &quot;Cube&quot;
&gt;&gt;&gt; bpy.ops.object.select_pattern(pattern=&quot;Cube*&quot;)
{'FINISHED'}