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[0]
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?
context.scene.objects.active = None
before the import. If after the import you want one of imported (and for most importers, selected) objects to be the active, set it to a member of:context.selected_objects
. $\endgroup$bpy.context.selected_objects
shows the right mesh being selected, butcontext.scene.objects.active
is None :/ Isn't that weird? $\endgroup$