I import an object into the scene via
bpy.ops.import_scene.obj. Before adding this object I have added some other objects in some other layers. However, after importing the new object
bpy.context.scene.objects.active does not change. I tried
bpy.ops.object.select_all(action='DESELECT') before importing the new object but it didn't work and the active object is still another object in the scene. I also tried the following before importing the new object:
for obj in self.scene.objects:
obj.select = False
bpy.context.scene.update() # Which seems unnecessary, but I do it just in case
But it still doesn't work.
To get around the issue temporarily, I did
bpy.context.scene.objects.active = bpy.context.scene.objects after importing the new object. This way I manually change the active object which is not ideal, and I should not be the case.
I am a bit confused why deselecting the objects does not work. I wonder, am I doing something wrong?