diff --git a/src/blenderbim/blenderbim/bim/module/spatial/operator.py b/src/blenderbim/blenderbim/bim/module/spatial/operator.py index 56de51f45b..2b9493e1d3 100644 --- a/src/blenderbim/blenderbim/bim/module/spatial/operator.py +++ b/src/blenderbim/blenderbim/bim/module/spatial/operator.py @@ -136,7 +136,7 @@ class CopyToContainer(bpy.types.Operator, tool.Ifc.Operator): old_to_new = {} containers = [tool.Ifc.get().by_id(c.ifc_definition_id) for c in sprops.containers if c.is_selected] for obj in context.selected_objects: - result_objs = core.copy_to_container(tool.Ifc, tool.Spatial, obj=obj, containers=containers) + result_objs = core.copy_to_container(tool.Ifc, tool.Collector, tool.Spatial, obj=obj, containers=containers) if result_objs: old_to_new[tool.Ifc.get_entity(obj)] = result_objs # Recreate decompositions diff --git a/src/blenderbim/blenderbim/core/spatial.py b/src/blenderbim/blenderbim/core/spatial.py index 35f5708a94..580c7e4099 100644 --- a/src/blenderbim/blenderbim/core/spatial.py +++ b/src/blenderbim/blenderbim/core/spatial.py @@ -60,10 +60,11 @@ def remove_container(ifc, collector, obj=None): collector.assign(obj) -def copy_to_container(ifc, spatial, obj=None, containers=None): +def copy_to_container(ifc, collector, spatial, obj=None, containers=None): element = ifc.get_entity(obj) if not element: return + collector.sync(obj) from_container = spatial.get_container(element) if from_container: matrix = spatial.get_relative_object_matrix(obj, ifc.get_object(from_container)) diff --git a/src/blenderbim/blenderbim/tool/collector.py b/src/blenderbim/blenderbim/tool/collector.py index a2be00654f..eaf0e57c7e 100644 --- a/src/blenderbim/blenderbim/tool/collector.py +++ b/src/blenderbim/blenderbim/tool/collector.py @@ -29,7 +29,12 @@ class Collector(blenderbim.core.tool.Collector): # This is the reverse of assign. It reads the Blender collection and figures out its IFC hierarchy element = tool.Ifc.get_entity(obj) - if element.is_a("IfcProject") or element.is_a("IfcGridAxis") or element.is_a("IfcOpeningElement"): + if ( + not element + or element.is_a("IfcProject") + or element.is_a("IfcGridAxis") + or element.is_a("IfcOpeningElement") + ): return if not obj.users_collection: diff --git a/src/blenderbim/test/core/test_spatial.py b/src/blenderbim/test/core/test_spatial.py index d8d52c9220..88210a9682 100644 --- a/src/blenderbim/test/core/test_spatial.py +++ b/src/blenderbim/test/core/test_spatial.py @@ -78,8 +78,9 @@ class TestRemoveContainer: class TestCopyToContainer: - def test_run(self, ifc, spatial): + def test_run(self, ifc, collector, spatial): ifc.get_entity("obj").should_be_called().will_return("element") + collector.sync("obj").should_be_called() spatial.get_container("element").should_be_called().will_return("container") ifc.get_object("container").should_be_called().will_return("container_obj") spatial.get_relative_object_matrix("obj", "container_obj").should_be_called().will_return("matrix") @@ -92,10 +93,11 @@ class TestCopyToContainer: spatial.disable_editing("obj").should_be_called() - subject.copy_to_container(ifc, spatial, obj="obj", containers=["to_container"]) + subject.copy_to_container(ifc, collector, spatial, obj="obj", containers=["to_container"]) - def test_using_an_absolute_matrix_if_there_is_no_from_container(self, ifc, spatial): + def test_using_an_absolute_matrix_if_there_is_no_from_container(self, ifc, collector, spatial): ifc.get_entity("obj").should_be_called().will_return("element") + collector.sync("obj").should_be_called() spatial.get_container("element").should_be_called().will_return(None) spatial.get_object_matrix("obj").should_be_called().will_return("matrix") @@ -107,7 +109,7 @@ class TestCopyToContainer: spatial.disable_editing("obj").should_be_called() - subject.copy_to_container(ifc, spatial, obj="obj", containers=["to_container"]) + subject.copy_to_container(ifc, collector, spatial, obj="obj", containers=["to_container"]) class TestSelectContainer: