Removing objects from collection with script works but gives an error I'm sorry in advance if my script looks really messy and not optimised, it's my first time using python or a dev language for that matters.
I've tried to setup a script that, among other things, create and assign objects to a LP collection by checking their names.
When I'm trying to unlink the object from the HP collection they were taken from, the script successfully does the task, but still return an error, here's the script :
#List all object in scene that ends with remeshed and select them
for obj in bpy.context.scene.objects: 
    if obj.name.endswith(&quot;remeshed&quot;): 
        obj.select_set(True)          

#Create collection with selected objects
bpy.ops.collection.create(name='LP') 

#Link collection to Scene Collection
bpy.context.scene.collection.children.link(bpy.data.collections[&quot;LP&quot;]) 

#Remove low poly objects from HP Collection
for obj in bpy.context.scene.objects: 
    if obj.name.endswith(&quot;remeshed&quot;):
        bpy.context.view_layer.objects.active = obj
        bpy.ops.collection.objects_remove(collection = 'HP')

I've also tried to use
bpy.context.scene.collection.objects.unlink(obj) withtout success even with the HP collection selected and active.
Here's the error message :
Traceback (most recent call last):
  File &quot;&lt;blender_console&gt;&quot;, line 4, in &lt;module&gt;
  File &quot;C:\Program Files\Blender Foundation\Blender 2.91\2.91\scripts\modules\bpy\ops.py&quot;, line 132, in __call__
    ret = _op_call(self.idname_py(), None, kw)
TypeError: Converting py args to operator properties:  enum &quot;HP&quot; not found in ('LP')

And as I was saying the script does what I want and unlink the object from the HP collection, but since it returns an error, it stop when running it.
Thanks in advance for all the help and advise you could give me.
I have enhanced and modified your code and, it works perfectly :

bl_info = {
    &quot;name&quot; : &quot;Clear Collection&quot;,
    &quot;author&quot; : &quot;CédricF&quot;,
    &quot;description&quot; : &quot;&quot;,
    &quot;blender&quot; : (2, 80, 0),
    &quot;version&quot; : (0, 0, 1),
    &quot;location&quot; : &quot;Sidebar(N)&gt;Clean Up&quot;,
    &quot;category&quot; : &quot;Clean Up&quot;
}

import bpy

from bpy.props import PointerProperty

#----------------------------------------
#MAIN PANEL
#----------------------------------------

class CLEARCOLLECTION_Property(bpy.types.PropertyGroup):

    ClrByNameEnd : bpy.props.StringProperty(name= &quot;All Objects Ending By&quot;, default=&quot;&quot;)
    ClrByCOLNameEnd : bpy.props.StringProperty(name= &quot;Collection&quot;, default=&quot;&quot;)

class CLEARCOLLECTION_PT_MAINPANEL(bpy.types.Panel):
    bl_idname = &quot;CLEARCOLLECTION_PT_CLEARBYNAMEEND&quot;
    bl_label = &quot;Clear By Name End&quot;
    bl_space_type = &quot;VIEW_3D&quot;
    bl_region_type = &quot;UI&quot;
    bl_category = &quot;Clean Up&quot;

    def draw(self, context):
        layout = self.layout

        scene = context.scene

        CLRCTool = scene.CLRTool

        row = layout.row()
        row.prop(CLRCTool, &quot;ClrByNameEnd&quot;, icon= &quot;TRASH&quot;)
        
        row = layout.row()
        row.prop(CLRCTool, &quot;ClrByCOLNameEnd&quot;, icon= &quot;TRASH&quot;)

        layout.operator(&quot;clearcollection.clearbyend&quot;, icon= &quot;TRASH&quot;)
        layout.operator(&quot;clearcollection.slecbyend&quot;, icon= &quot;RESTRICT_SELECT_OFF&quot;)
        
#----------------------------------------
#CLEAR OBJECTS
#----------------------------------------

class CLEARCOLLECTION_OT_CLEAR(bpy.types.Operator):
    bl_idname = &quot;clearcollection.clearbyend&quot;
    bl_label = &quot;Clear Objects&quot;
    bl_description = &quot;Clears objects which end with the given input&quot;
    bl_options = {&quot;REGISTER&quot;}

    def execute(self, context):
    
        scene = context.scene

        CLRCTool = scene.CLRTool

        for obj in bpy.context.scene.objects: 
            if CLRCTool.ClrByNameEnd != &quot;&quot;:
                if obj.name.endswith(CLRCTool.ClrByNameEnd): 
                    bpy.data.objects.remove(obj)


        for obj in bpy.context.scene.objects:
            if CLRCTool.ClrByCOLNameEnd != &quot;&quot;:
                for objc in bpy.data.collections[CLRCTool.ClrByCOLNameEnd].all_objects:
                    if CLRCTool.ClrByNameEnd != &quot;&quot;:
                        if obj.name.endswith(CLRCTool.ClrByNameEnd): 
                            bpy.data.objects.remove(obj)
        
        return {&quot;FINISHED&quot;}

#----------------------------------------
#SELECT OBJECTS
#----------------------------------------

class CLEARCOLLECTION_OT_SELEC(bpy.types.Operator):
    bl_idname = &quot;clearcollection.slecbyend&quot;
    bl_label = &quot;Select&quot;
    bl_description = &quot;Selects objects which end with the given input&quot;
    bl_options = {&quot;REGISTER&quot;}

    def execute(self, context):
    
        scene = context.scene

        CLRCTool = scene.CLRTool

        for obj in bpy.context.scene.objects: 
            if CLRCTool.ClrByNameEnd != &quot;&quot;:
                if obj.name.endswith(CLRCTool.ClrByNameEnd): 
                    obj.select_set(True)


        for obj in bpy.context.scene.objects:
            if CLRCTool.ClrByCOLNameEnd != &quot;&quot;:
                for objc in bpy.data.collections[CLRCTool.ClrByCOLNameEnd].all_objects:
                    if CLRCTool.ClrByNameEnd != &quot;&quot;:
                        if obj.name.endswith(CLRCTool.ClrByNameEnd): 
                            obj.select_set(True)
        
        return {&quot;FINISHED&quot;}

classes = [CLEARCOLLECTION_Property, CLEARCOLLECTION_OT_CLEAR, CLEARCOLLECTION_OT_SELEC, CLEARCOLLECTION_PT_MAINPANEL]

def register():
    
    for cls in classes :
        bpy.utils.register_class(cls)
        bpy.types.Scene.CLRTool = PointerProperty(type= CLEARCOLLECTION_Property)


def unregister():
    
    for cls in classes :
        bpy.utils.unregister_class(cls)
        #del bpy.types.Scene.CLRTool


if __name__ == &quot;__main__&quot;:
    register()