diff --git a/src/bonsai/bonsai/tool/drawing.py b/src/bonsai/bonsai/tool/drawing.py index e9f6ec315d..93dfbaf732 100644 --- a/src/bonsai/bonsai/tool/drawing.py +++ b/src/bonsai/bonsai/tool/drawing.py @@ -1779,6 +1779,7 @@ class Drawing(bonsai.core.tool.Drawing): @classmethod def activate_drawing(cls, camera: bpy.types.Object) -> None: selected_objects_before = bpy.context.selected_objects + non_ifc_objects_hide = {o: o.hide_get() for o in bpy.context.view_layer.objects if not tool.Ifc.get_entity(o)} # Sync viewport objects visibility with selectors from EPset_Drawing/Include and /Exclude drawing = tool.Ifc.get_entity(camera) @@ -1859,11 +1860,12 @@ class Drawing(bonsai.core.tool.Drawing): element_obj_names.add(obj.name) # Note that render visibility is only set on drawing generation time for speed. - [ - obj.hide_set(False) # Show the object - for obj in bpy.context.view_layer.objects - if obj.name in element_obj_names or not tool.Ifc.get_entity(obj) - ] + for obj in bpy.context.view_layer.objects: + if obj.name in element_obj_names: + obj.hide_set(False) # Show the object + continue + if (hide := non_ifc_objects_hide.get(obj)) is not None: + obj.hide_set(hide) cls.import_camera_props(drawing, camera.data) diff --git a/src/bonsai/test/bim/feature/drawing.feature b/src/bonsai/test/bim/feature/drawing.feature index 762be4e8ef..f5839dfe8e 100644 --- a/src/bonsai/test/bim/feature/drawing.feature +++ b/src/bonsai/test/bim/feature/drawing.feature @@ -51,6 +51,29 @@ Scenario: Create drawing after deleting a duplicated object When I press "bim.create_drawing" Then nothing happens +Scenario: Activate drawing preserves visibility for non-ifc objects + Given an empty IFC project + And I add a cube + And I add a cube + And the object "Cube" is visible + And the object "Cube.001" is not visible + And I press "bim.add_drawing" + And the variable "drawing" is "IfcStore.get_file().by_type('IfcAnnotation')[0].id()" + And I set "scene.DocProperties.active_drawing_index" to "0" + When I press "bim.activate_drawing(drawing={drawing})" + Then the object "Cube" is visible + And the object "Cube.001" is not visible + +Scenario: Activate drawing preserves selection + Given an empty IFC project + And I add a cube + And the object "Cube" is selected + And I press "bim.add_drawing" + And the variable "drawing" is "IfcStore.get_file().by_type('IfcAnnotation')[0].id()" + And I set "scene.DocProperties.active_drawing_index" to "0" + When I press "bim.activate_drawing(drawing={drawing})" + Then the object "Cube" is selected + Scenario: Remove drawing Given an empty IFC project And I add a cube diff --git a/src/bonsai/test/bim/test_feature.py b/src/bonsai/test/bim/test_feature.py index 0d3194154f..c9f3a99265 100644 --- a/src/bonsai/test/bim/test_feature.py +++ b/src/bonsai/test/bim/test_feature.py @@ -840,6 +840,30 @@ def the_object_name_is_not_a_void(name): assert False, "A void was found" +@given(parsers.parse('the object "{name}" is visible')) +def given_the_object_name_is_visible(name): + obj = the_object_name_exists(name) + obj.hide_set(False) + + +@given(parsers.parse('the object "{name}" is not visible')) +def given_the_object_name_is_not_visible(name): + obj = the_object_name_exists(name) + obj.hide_set(True) + + +@then(parsers.parse('the object "{name}" is visible')) +def the_object_name_is_visible(name): + obj = the_object_name_exists(name) + assert obj.hide_get() == False + + +@then(parsers.parse('the object "{name}" is not visible')) +def the_object_name_is_not_visible(name): + obj = the_object_name_exists(name) + assert obj.hide_get() == True + + @then(parsers.parse('the object "{name}" is an "{ifc_class}"')) def the_object_name_is_an_ifc_class(name, ifc_class): ifc = an_ifc_file_exists()