Don't consider context.selected_objects a normal python list.
Some points I thought it was worth mentioning: In your question setting select_objects = context.selected_objects
returns a copy of the list instead of a reference.
>>> C.selected_objects
[bpy.data.objects['Cube'], bpy.data.objects['Lamp'], bpy.data.objects['Camera']]
>>> s = C.selected_objects # s is a copy
>>> l = s # l is a reference
>>> s.pop() # remove last element from s
bpy.data.objects['Camera']
>>> s
[bpy.data.objects['Cube'], bpy.data.objects['Lamp']]
>>> l
[bpy.data.objects['Cube'], bpy.data.objects['Lamp']]
>>> C.selected_objects
[bpy.data.objects['Cube'], bpy.data.objects['Lamp'], bpy.data.objects['Camera']]
>>>
If you wish to manipulate the context.selected_objects
list,
Don't use .remove(obj)
to remove objects. Objects in the this list have their select
property set to True. It is useful to be able to manipulate this list as it is used directly by a lot of operators.
As an example in the py console.
>>> C.selected_objects
[bpy.data.objects['Cube']]
>>> C.selected_objects.remove(C.object)
>>> C.selected_objects
[bpy.data.objects['Cube']]
>>> C.object.select
True
>>> C.selected_objects.clear()
>>> C.selected_objects
[bpy.data.objects['Cube']]
Notice the "Cube" object is neither removed, nor set as selected.
Can remove from the selected objects list by negating select.
>>> for o in C.selected_objects:
... o.select = False
...
>>> C.selected_objects
[]
>>> C.object
bpy.data.objects['Cube']
which removes the object from the list. Note it is still the active object.
This will remove all but mesh and curve objects from selected objects.
import bpy
context = bpy.context
for o in context.selected_objects:
o.select = o.type in ('MESH', 'CURVE')
but remember you may need to set the active object context.scene.objects.active = obj
to one that is still in the list after deselecting if you are going to call an operator.