Alembic import: select imported objects
authorSybren A. Stüvel <sybren@stuvel.eu>
Thu, 20 Apr 2017 10:01:31 +0000 (12:01 +0200)
committerSybren A. Stüvel <sybren@stuvel.eu>
Thu, 20 Apr 2017 10:01:31 +0000 (12:01 +0200)
When the Alembic import is finished, all imported objects are selected.

source/blender/alembic/intern/alembic_capi.cc
tests/python/bl_alembic_import_test.py

index 104b19beaf08fe8b50482fe85b571dadb1051eec..e44f66b7e56460eaa568ec87c821e6f751e72f5e 100644 (file)
@@ -795,13 +795,16 @@ static void import_endjob(void *user_data)
        }
        else {
                /* Add object to scene. */
+               Base *base;
+
                BKE_scene_base_deselect_all(data->scene);
 
                for (iter = data->readers.begin(); iter != data->readers.end(); ++iter) {
                        Object *ob = (*iter)->object();
                        ob->lay = data->scene->lay;
 
-                       BKE_scene_base_add(data->scene, ob);
+                       base = BKE_scene_base_add(data->scene, ob);
+                       BKE_scene_base_select(data->scene, base);
 
                        DAG_id_tag_update_ex(data->bmain, &ob->id, OB_RECALC_OB | OB_RECALC_DATA | OB_RECALC_TIME);
                }
index fd43e404e82df49d7d99d55e17c359d2da377880..cd23183ec0677d8d2d4489106cea44041e5a4f82 100644 (file)
@@ -63,6 +63,28 @@ class SimpleImportTest(unittest.TestCase):
         self.assertEqual(objects['Cube_003'], objects['Cube_005'].parent)
         self.assertEqual(objects['Cube_003'], objects['Cube_006'].parent)
 
+    def test_select_after_import(self):
+        # Add a sphere, so that there is something in the scene, selected, and active,
+        # before we do the Alembic import.
+        bpy.ops.mesh.primitive_uv_sphere_add()
+        sphere = bpy.context.active_object
+        self.assertEqual('Sphere', sphere.name)
+        self.assertEqual([sphere], bpy.context.selected_objects)
+
+        bpy.ops.wm.alembic_import(
+            filepath=str(self.testdir / "cubes-hierarchy.abc"),
+            as_background_job=False)
+
+        # The active object is probably the first one that was imported, but this
+        # behaviour is not defined. At least it should be one of the cubes, and
+        # not the sphere.
+        self.assertNotEqual(sphere, bpy.context.active_object)
+        self.assertTrue('Cube' in bpy.context.active_object.name)
+
+        # All cubes should be selected, but the sphere shouldn't be.
+        for ob in bpy.data.objects:
+            self.assertEqual('Cube' in ob.name, ob.select)
+
 
 def main():
     global args