Fix failing collector tests to align with new behaviour

This commit is contained in:
Dion Moult
2024-06-28 21:15:53 +10:00
parent e59cd80868
commit 008fa70345
5 changed files with 91 additions and 143 deletions
+1 -1
View File
@@ -27,10 +27,10 @@ import sys
IN_BLENDER = sys.modules.get("bpy", None) IN_BLENDER = sys.modules.get("bpy", None)
if IN_BLENDER: if IN_BLENDER:
import bpy import bpy
import addon_utils
import platform import platform
import traceback import traceback
import webbrowser import webbrowser
import addon_utils
from collections import deque from collections import deque
bl_info = { bl_info = {
-1
View File
@@ -169,7 +169,6 @@ class Clash:
@interface @interface
class Collector: class Collector:
def assign(cls, obj): pass def assign(cls, obj): pass
def sync(cls, obj): pass
@interface @interface
+6 -1
View File
@@ -58,7 +58,11 @@ class Collector(blenderbim.core.tool.Collector):
cls.link_to_collection_safe(obj, collection) cls.link_to_collection_safe(obj, collection)
project_obj = tool.Ifc.get_object(tool.Ifc.get().by_type("IfcProject")[0]) project_obj = tool.Ifc.get_object(tool.Ifc.get().by_type("IfcProject")[0])
cls.link_to_collection_safe(collection, project_obj.BIMObjectProperties.collection) cls.link_to_collection_safe(collection, project_obj.BIMObjectProperties.collection)
elif tool.Ifc.get_schema() != "IFC2X3" and element.is_a("IfcSpatialElement"): elif (
tool.Ifc.get_schema() != "IFC2X3"
and element.is_a("IfcSpatialElement")
and not element.is_a("IfcSpatialZone")
):
if collection := cls._create_own_collection(obj): if collection := cls._create_own_collection(obj):
cls.link_to_collection_safe(obj, collection) cls.link_to_collection_safe(obj, collection)
project_obj = tool.Ifc.get_object(tool.Ifc.get().by_type("IfcProject")[0]) project_obj = tool.Ifc.get_object(tool.Ifc.get().by_type("IfcProject")[0])
@@ -103,6 +107,7 @@ class Collector(blenderbim.core.tool.Collector):
def _create_own_collection(cls, obj: bpy.types.Object) -> bpy.types.Collection: def _create_own_collection(cls, obj: bpy.types.Object) -> bpy.types.Collection:
"""get or create own collection for the element""" """get or create own collection for the element"""
if obj.BIMObjectProperties.collection: if obj.BIMObjectProperties.collection:
obj.BIMObjectProperties.collection.name = obj.name
return return
collection = bpy.data.collections.new(obj.name) collection = bpy.data.collections.new(obj.name)
obj.BIMObjectProperties.collection = collection obj.BIMObjectProperties.collection = collection
+12
View File
@@ -57,6 +57,18 @@ class NewIfc:
bpy.ops.bim.create_project() bpy.ops.bim.create_project()
class NewIfc4X3:
@pytest.fixture(autouse=True)
def setup(self):
IfcStore.purge()
bpy.ops.wm.read_homefile(app_template="")
bpy.data.batch_remove(bpy.data.objects)
bpy.ops.outliner.orphans_purge(do_local_ids=True, do_linked_ids=True, do_recursive=True)
blenderbim.bim.handler.load_post(None)
bpy.context.scene.BIMProjectProperties.export_schema = "IFC4X3_ADD2"
bpy.ops.bim.create_project()
def scenario(function): def scenario(function):
def subfunction(self): def subfunction(self):
run(function(self)) run(function(self))
+72 -140
View File
@@ -23,7 +23,7 @@ import ifcopenshell.util.element
import blenderbim.core.tool import blenderbim.core.tool
import blenderbim.tool as tool import blenderbim.tool as tool
from blenderbim.tool.collector import Collector as subject from blenderbim.tool.collector import Collector as subject
from test.bim.bootstrap import NewFile from test.bim.bootstrap import NewFile, NewIfc, NewIfc4X3
class TestImplementsTool(NewFile): class TestImplementsTool(NewFile):
@@ -31,9 +31,8 @@ class TestImplementsTool(NewFile):
assert isinstance(subject(), blenderbim.core.tool.Collector) assert isinstance(subject(), blenderbim.core.tool.Collector)
class TestAssign(NewFile): class TestAssign(NewIfc):
def test_in_decomposition_mode_walls_are_placed_in_its_spatial_collection(self): def test_walls_are_placed_in_its_spatial_collection(self):
bpy.ops.bim.create_project()
wall_obj = bpy.data.objects.new("Object", None) wall_obj = bpy.data.objects.new("Object", None)
wall_element = tool.Ifc.get().createIfcWall() wall_element = tool.Ifc.get().createIfcWall()
tool.Ifc.link(wall_element, wall_obj) tool.Ifc.link(wall_element, wall_obj)
@@ -45,21 +44,19 @@ class TestAssign(NewFile):
relating_structure=tool.Ifc.get().by_type("IfcSite")[0], relating_structure=tool.Ifc.get().by_type("IfcSite")[0],
) )
subject.assign(wall_obj) subject.assign(wall_obj)
assert len(wall_obj.users_collection) == 1 assert len(wall_obj.users_collection) == 2
assert "IfcSite" in wall_obj.users_collection[0].name assert "IfcSite" in wall_obj.users_collection[0].name
def test_in_decomposition_mode_walls_are_placed_in_the_project_if_not_decomposes(self): def test_walls_are_unsorted_if_not_decomposes(self):
bpy.ops.bim.create_project()
wall_obj = bpy.data.objects.new("Object", None) wall_obj = bpy.data.objects.new("Object", None)
wall_element = tool.Ifc.get().createIfcWall() wall_element = tool.Ifc.get().createIfcWall()
tool.Ifc.link(wall_element, wall_obj) tool.Ifc.link(wall_element, wall_obj)
bpy.context.scene.collection.objects.link(wall_obj) bpy.context.scene.collection.objects.link(wall_obj)
subject.assign(wall_obj) subject.assign(wall_obj)
assert len(wall_obj.users_collection) == 1 assert len(wall_obj.users_collection) == 2
assert "IfcProject" in wall_obj.users_collection[0].name assert "Unsorted" in wall_obj.users_collection[0].name
def test_in_decomposition_mode_spatial_structure_elements_are_placed_in_a_collection_of_the_same_name(self): def test_spatial_structure_elements_are_placed_in_a_collection_of_the_same_name(self):
bpy.ops.bim.create_project()
space_obj = bpy.data.objects.new("IfcSpace/Name", None) space_obj = bpy.data.objects.new("IfcSpace/Name", None)
space_element = tool.Ifc.get().createIfcSpace() space_element = tool.Ifc.get().createIfcSpace()
tool.Ifc.link(space_element, space_obj) tool.Ifc.link(space_element, space_obj)
@@ -71,11 +68,10 @@ class TestAssign(NewFile):
products=[space_element], products=[space_element],
) )
subject.assign(space_obj) subject.assign(space_obj)
assert len(space_obj.users_collection) == 1 assert len(space_obj.users_collection) == 2
assert space_obj.users_collection[0].name == space_obj.name assert space_obj.users_collection[0].name == space_obj.name
def test_in_decomposition_mode_multiple_assigns_do_not_create_duplicate_spatial_structure_collections(self): def test_multiple_assigns_do_not_create_duplicate_spatial_structure_collections(self):
bpy.ops.bim.create_project()
space_obj = bpy.data.objects.new("IfcSpace/Name", None) space_obj = bpy.data.objects.new("IfcSpace/Name", None)
space_element = tool.Ifc.get().createIfcSpace() space_element = tool.Ifc.get().createIfcSpace()
tool.Ifc.link(space_element, space_obj) tool.Ifc.link(space_element, space_obj)
@@ -93,8 +89,7 @@ class TestAssign(NewFile):
assert not bpy.data.collections.get("IfcSpace/Name.001") assert not bpy.data.collections.get("IfcSpace/Name.001")
assert not bpy.data.collections.get("IfcSite/My Site.001") assert not bpy.data.collections.get("IfcSite/My Site.001")
def test_in_decomposition_mode_spatial_zone_elements_are_not_placed_in_a_collection_of_the_same_name(self): def test_spatial_zone_elements_are_not_placed_in_a_collection_of_the_same_name(self):
bpy.ops.bim.create_project()
space_obj = bpy.data.objects.new("IfcSpaceZone/Name", None) space_obj = bpy.data.objects.new("IfcSpaceZone/Name", None)
space_element = tool.Ifc.get().createIfcSpatialZone() space_element = tool.Ifc.get().createIfcSpatialZone()
tool.Ifc.link(space_element, space_obj) tool.Ifc.link(space_element, space_obj)
@@ -106,38 +101,48 @@ class TestAssign(NewFile):
products=[space_element], products=[space_element],
) )
subject.assign(space_obj) subject.assign(space_obj)
assert len(space_obj.users_collection) == 1 assert len(space_obj.users_collection) == 2
assert space_obj.users_collection[0].name != space_obj.name assert space_obj.users_collection[0].name != space_obj.name
def test_in_decomposition_mode_aggregates_are_placed_in_a_collection_of_the_same_name(self): def test_aggregates_are_also_placed_in_their_container(self):
bpy.ops.bim.create_project()
element_obj = bpy.data.objects.new("IfcElementAssembly/Name", None) element_obj = bpy.data.objects.new("IfcElementAssembly/Name", None)
element = tool.Ifc.get().createIfcElementAssembly() element = tool.Ifc.get().createIfcElementAssembly()
subelement_obj = bpy.data.objects.new("IfcBeam/Name", None) subelement_obj = bpy.data.objects.new("IfcBeam/Name", None)
subelement = tool.Ifc.get().createIfcBeam() subelement = tool.Ifc.get().createIfcBeam()
tool.Ifc.link(element, element_obj) tool.Ifc.link(element, element_obj)
tool.Ifc.link(subelement, subelement_obj)
bpy.context.scene.collection.objects.link(element_obj) bpy.context.scene.collection.objects.link(element_obj)
bpy.context.scene.collection.objects.link(subelement_obj)
ifcopenshell.api.run( ifcopenshell.api.run(
"aggregate.assign_object", "aggregate.assign_object",
tool.Ifc.get(), tool.Ifc.get(),
relating_object=element, relating_object=element,
products=[subelement], products=[subelement],
) )
ifcopenshell.api.run(
"spatial.assign_container",
tool.Ifc.get(),
products=[element],
relating_structure=tool.Ifc.get().by_type("IfcSite")[0],
)
subject.assign(element_obj) subject.assign(element_obj)
assert len(element_obj.users_collection) == 1 subject.assign(subelement_obj)
assert element_obj.users_collection[0].name == element_obj.name assert len(element_obj.users_collection) == 2
assert len(subelement_obj.users_collection) == 2
assert "IfcSite" in element_obj.users_collection[0].name
assert "IfcSite" in subelement_obj.users_collection[0].name
def test_in_decomposition_mode_projects_are_placed_in_a_collection_of_the_same_name(self): def test_projects_are_placed_in_a_collection_of_the_same_name(self):
tool.Ifc.set(ifcopenshell.file()) tool.Ifc.set(ifcopenshell.file())
element_obj = bpy.data.objects.new("IfcProject/Name", None) element_obj = bpy.data.objects.new("IfcProject/Name", None)
element = tool.Ifc.get().createIfcProject() element = tool.Ifc.get().createIfcProject()
tool.Ifc.link(element, element_obj) tool.Ifc.link(element, element_obj)
bpy.context.scene.collection.objects.link(element_obj) bpy.context.scene.collection.objects.link(element_obj)
subject.assign(element_obj) subject.assign(element_obj)
assert len(element_obj.users_collection) == 1 assert len(element_obj.users_collection) == 2
assert element_obj.users_collection[0].name == element_obj.name assert element_obj.users_collection[0].name == element_obj.name
def test_in_decomposition_mode_multiple_assigns_do_not_create_duplicate_collections(self): def test_multiple_assigns_do_not_create_duplicate_collections(self):
tool.Ifc.set(ifcopenshell.file()) tool.Ifc.set(ifcopenshell.file())
element_obj = bpy.data.objects.new("IfcProject/Name", None) element_obj = bpy.data.objects.new("IfcProject/Name", None)
element = tool.Ifc.get().createIfcProject() element = tool.Ifc.get().createIfcProject()
@@ -148,12 +153,11 @@ class TestAssign(NewFile):
assert bpy.data.collections.get("IfcProject/Name") assert bpy.data.collections.get("IfcProject/Name")
assert not bpy.data.collections.get("IfcProject/Name.001") assert not bpy.data.collections.get("IfcProject/Name.001")
def test_in_decomposition_mode_existing_collections_are_reassigned_to_the_correct_place_in_the_hierarchy(self): def test_own_collections_are_retained_and_name_synced(self):
bpy.ops.bim.create_project()
space_obj = bpy.data.objects.new("IfcSpace/Name", None) space_obj = bpy.data.objects.new("IfcSpace/Name", None)
space_element = tool.Ifc.get().createIfcSpace() space_element = tool.Ifc.get().createIfcSpace()
tool.Ifc.link(space_element, space_obj) tool.Ifc.link(space_element, space_obj)
space_collection = bpy.data.collections.new("IfcSpace/Name") space_collection = bpy.data.collections.new("Foobar")
bpy.context.scene.collection.children.link(space_collection) bpy.context.scene.collection.children.link(space_collection)
space_obj.BIMObjectProperties.collection = space_collection space_obj.BIMObjectProperties.collection = space_collection
space_collection.objects.link(space_obj) space_collection.objects.link(space_obj)
@@ -164,72 +168,32 @@ class TestAssign(NewFile):
products=[space_element], products=[space_element],
) )
subject.assign(space_obj) subject.assign(space_obj)
assert bpy.context.scene.collection.children.find(space_collection.name) == -1 assert bpy.context.scene.collection.children.find(space_collection.name) != -1
assert bpy.data.collections.get("IfcSite/My Site").children.find(space_collection.name) != -1 assert bpy.data.collections.get("IfcSite/My Site").children.find(space_collection.name) == -1
assert bpy.data.collections.get("IfcProject/My Project").children.find(space_collection.name) == -1
assert bpy.context.scene.collection.children.find(space_collection.name) != -1
assert space_collection.objects.find(space_obj.name) != -1
assert space_collection.name == "IfcSpace/Name"
def test_in_decomposition_mode_aggregates_subelements_are_placed_in_the_aggregates_collection(self): def test_types_are_placed_in_the_types_collection(self):
bpy.ops.bim.create_project()
element_obj = bpy.data.objects.new("IfcElementAssembly/Name", None)
element = tool.Ifc.get().createIfcElementAssembly()
subelement_obj = bpy.data.objects.new("IfcBeam/Name", None)
subelement = tool.Ifc.get().createIfcBeam()
tool.Ifc.link(element, element_obj)
tool.Ifc.link(subelement, subelement_obj)
bpy.context.scene.collection.objects.link(element_obj)
ifcopenshell.api.run(
"aggregate.assign_object",
tool.Ifc.get(),
relating_object=element,
products=[subelement],
)
subject.assign(element_obj)
subject.assign(subelement_obj)
assert subelement_obj.users_collection[0].name == element_obj.name
def test_in_decomposition_mode_aggregates_subelements_are_placed_in_the_spatial_collection_as_a_fallback(self):
# The aggregate object may not exist in all scenarios, such as when it is filtered out
bpy.ops.bim.create_project()
element = tool.Ifc.get().createIfcElementAssembly()
subelement_obj = bpy.data.objects.new("IfcBeam/Name", None)
subelement = tool.Ifc.get().createIfcBeam()
tool.Ifc.link(subelement, subelement_obj)
ifcopenshell.api.run(
"spatial.assign_container",
tool.Ifc.get(),
products=[element],
relating_structure=tool.Ifc.get().by_type("IfcSite")[0],
)
ifcopenshell.api.run(
"aggregate.assign_object",
tool.Ifc.get(),
relating_object=element,
products=[subelement],
)
subject.assign(subelement_obj)
assert subelement_obj.users_collection[0].name == "IfcSite/My Site"
def test_in_decomposition_mode_types_are_placed_in_the_types_collection(self):
bpy.ops.bim.create_project()
element_obj = bpy.data.objects.new("IfcWallType/Name", None) element_obj = bpy.data.objects.new("IfcWallType/Name", None)
element = tool.Ifc.get().createIfcWallType() element = tool.Ifc.get().createIfcWallType()
tool.Ifc.link(element, element_obj) tool.Ifc.link(element, element_obj)
bpy.context.scene.collection.objects.link(element_obj) bpy.context.scene.collection.objects.link(element_obj)
subject.assign(element_obj) subject.assign(element_obj)
assert element_obj.users_collection[0].name == "Types" assert element_obj.users_collection[0].name == "IfcTypeProduct"
assert bpy.data.collections.get("IfcProject/My Project").children.get("Types") assert bpy.data.collections.get("IfcProject/My Project").children.get("IfcTypeProduct")
def test_in_decomposition_mode_openings_are_placed_in_the_openings_collection(self): def test_openings_are_placed_in_the_openings_collection(self):
bpy.ops.bim.create_project()
element_obj = bpy.data.objects.new("IfcOpeningElement/Name", None) element_obj = bpy.data.objects.new("IfcOpeningElement/Name", None)
element = tool.Ifc.get().createIfcOpeningElement() element = tool.Ifc.get().createIfcOpeningElement()
tool.Ifc.link(element, element_obj) tool.Ifc.link(element, element_obj)
bpy.context.scene.collection.objects.link(element_obj) bpy.context.scene.collection.objects.link(element_obj)
subject.assign(element_obj) subject.assign(element_obj)
assert element_obj.users_collection[0].name == "IfcOpeningElements" assert element_obj.users_collection[0].name == "IfcOpeningElement"
assert bpy.data.collections.get("IfcProject/My Project").children.get("IfcOpeningElements") assert bpy.data.collections.get("IfcProject/My Project").children.get("IfcOpeningElement")
def test_in_decomposition_mode_grids_are_placed_in_their_own_collection(self): def test_grids_are_placed_in_their_container(self):
bpy.ops.bim.create_project()
element_obj = bpy.data.objects.new("IfcGrid/Name", None) element_obj = bpy.data.objects.new("IfcGrid/Name", None)
element = tool.Ifc.get().createIfcGrid() element = tool.Ifc.get().createIfcGrid()
tool.Ifc.link(element, element_obj) tool.Ifc.link(element, element_obj)
@@ -241,11 +205,9 @@ class TestAssign(NewFile):
) )
bpy.context.scene.collection.objects.link(element_obj) bpy.context.scene.collection.objects.link(element_obj)
subject.assign(element_obj) subject.assign(element_obj)
assert element_obj.users_collection[0].name == "IfcGrid/Name" assert element_obj.users_collection[0].name == "IfcSite/My Site"
assert bpy.data.collections.get("IfcSite/My Site").children.get("IfcGrid/Name")
def test_in_decomposition_mode_grids_axes_are_placed_in_an_axis_collection_of_the_grid(self): def test_grids_axes_are_placed_in_the_grids_container(self):
bpy.ops.bim.create_project()
element_obj = bpy.data.objects.new("IfcGrid/Name", None) element_obj = bpy.data.objects.new("IfcGrid/Name", None)
axis_obj = bpy.data.objects.new("IfcGrid/Name", None) axis_obj = bpy.data.objects.new("IfcGrid/Name", None)
axis = tool.Ifc.get().createIfcGridAxis() axis = tool.Ifc.get().createIfcGridAxis()
@@ -261,11 +223,9 @@ class TestAssign(NewFile):
bpy.context.scene.collection.objects.link(element_obj) bpy.context.scene.collection.objects.link(element_obj)
subject.assign(element_obj) subject.assign(element_obj)
subject.assign(axis_obj) subject.assign(axis_obj)
assert axis_obj.users_collection[0].name == "UAxes" assert axis_obj.users_collection[0].name == "IfcSite/My Site"
assert bpy.data.collections.get("IfcGrid/Name").children.get("UAxes")
def test_in_decomposition_mode_drawings_are_placed_in_a_group_in_a_views_collection(self): def test_drawings_are_placed_in_their_own_collection(self):
bpy.ops.bim.create_project()
element_obj = bpy.data.objects.new("IfcAnnotation/DRAWING", None) element_obj = bpy.data.objects.new("IfcAnnotation/DRAWING", None)
element = tool.Ifc.get().createIfcAnnotation(ObjectType="DRAWING") element = tool.Ifc.get().createIfcAnnotation(ObjectType="DRAWING")
tool.Ifc.link(element, element_obj) tool.Ifc.link(element, element_obj)
@@ -276,11 +236,10 @@ class TestAssign(NewFile):
subject.assign(element_obj) subject.assign(element_obj)
assert element_obj.users_collection[0].name == "IfcAnnotation/DRAWING" assert element_obj.users_collection[0].name == "IfcAnnotation/DRAWING"
assert bpy.data.collections.get("Views").children.get("IfcAnnotation/DRAWING") assert bpy.data.collections.get("IfcProject/My Project").children.get("IfcAnnotation/DRAWING")
assert bpy.data.collections.get("IfcProject/My Project").children.get("Views")
def test_in_decomposition_mode_annotations_are_placed_in_a_group_in_a_views_collection(self): def test_annotations_are_placed_in_their_drawings_collection(self):
self.test_in_decomposition_mode_drawings_are_placed_in_a_group_in_a_views_collection() self.test_drawings_are_placed_in_their_own_collection()
ifc_file = tool.Ifc.get() ifc_file = tool.Ifc.get()
element_obj = bpy.data.objects.new("IfcAnnotation/Name", None) element_obj = bpy.data.objects.new("IfcAnnotation/Name", None)
@@ -293,63 +252,36 @@ class TestAssign(NewFile):
subject.assign(element_obj) subject.assign(element_obj)
assert element_obj.users_collection[0].name == "IfcAnnotation/DRAWING" assert element_obj.users_collection[0].name == "IfcAnnotation/DRAWING"
def test_in_decomposition_mode_structural_members_are_placed_in_a_members_collection(self): def test_structural_members_are_placed_in_a_members_collection(self):
bpy.ops.bim.create_project()
element_obj = bpy.data.objects.new("IfcStructuralCurveMember/Name", None) element_obj = bpy.data.objects.new("IfcStructuralCurveMember/Name", None)
element = tool.Ifc.get().createIfcStructuralCurveMember() element = tool.Ifc.get().createIfcStructuralCurveMember()
tool.Ifc.link(element, element_obj) tool.Ifc.link(element, element_obj)
subject.assign(element_obj) subject.assign(element_obj)
assert element_obj.users_collection[0].name == "Members" assert element_obj.users_collection[0].name == "IfcStructuralItem"
assert bpy.data.collections.get("StructuralItems").children.get("Members") assert bpy.data.collections.get("IfcProject/My Project").children.get("IfcStructuralItem")
assert bpy.data.collections.get("IfcProject/My Project").children.get("StructuralItems")
def test_in_decomposition_mode_structural_connections_are_placed_in_a_connections_collection(self): def test_structural_connections_are_placed_in_a_connections_collection(self):
bpy.ops.bim.create_project()
element_obj = bpy.data.objects.new("IfcStructuralCurveConnection/Name", None) element_obj = bpy.data.objects.new("IfcStructuralCurveConnection/Name", None)
element = tool.Ifc.get().createIfcStructuralCurveConnection() element = tool.Ifc.get().createIfcStructuralCurveConnection()
tool.Ifc.link(element, element_obj) tool.Ifc.link(element, element_obj)
subject.assign(element_obj) subject.assign(element_obj)
assert element_obj.users_collection[0].name == "Connections" assert element_obj.users_collection[0].name == "IfcStructuralItem"
assert bpy.data.collections.get("StructuralItems").children.get("Connections") assert bpy.data.collections.get("IfcProject/My Project").children.get("IfcStructuralItem")
assert bpy.data.collections.get("IfcProject/My Project").children.get("StructuralItems")
class TestSync(NewFile): class TestAssignIFC4X3(NewIfc4X3):
def test_doing_nothing_if_the_object_has_no_collection(self): def test_linear_positioning_elements_are_placed_in_a_special_collection(self):
bpy.ops.bim.create_project() element_obj = bpy.data.objects.new("Name", None)
wall_obj = bpy.data.objects.new("Object", None) element = tool.Ifc.get().createIfcAlignment()
wall_element = tool.Ifc.get().createIfcWall() tool.Ifc.link(element, element_obj)
tool.Ifc.link(wall_element, wall_obj) subject.assign(element_obj)
subject.sync(wall_obj) assert element_obj.users_collection[0].name == "IfcLinearPositioningElement"
assert not wall_obj.users_collection assert bpy.data.collections.get("IfcProject/My Project").children.get("IfcLinearPositioningElement")
def test_in_decomposition_mode_elements_can_be_in_spatial_containers(self): def test_referents_are_placed_in_a_special_collection(self):
bpy.ops.bim.create_project() element_obj = bpy.data.objects.new("Name", None)
wall_obj = bpy.data.objects.new("Object", None) element = tool.Ifc.get().createIfcReferent()
wall_element = tool.Ifc.get().createIfcWall() tool.Ifc.link(element, element_obj)
tool.Ifc.link(wall_element, wall_obj) subject.assign(element_obj)
bpy.data.collections.get("IfcSite/My Site").objects.link(wall_obj) assert element_obj.users_collection[0].name == "IfcReferent"
subject.sync(wall_obj) assert bpy.data.collections.get("IfcProject/My Project").children.get("IfcReferent")
assert ifcopenshell.util.element.get_container(wall_element).is_a("IfcSite")
def test_in_decomposition_mode_elements_can_aggregate(self):
bpy.ops.bim.create_project()
obj = bpy.data.objects.new("IfcBuildingStorey/Name", None)
col = bpy.data.collections.new("IfcBuildingStorey/Name")
obj.BIMObjectProperties.collection = col
col.BIMCollectionProperties.obj = obj
element = tool.Ifc.get().createIfcBuildingStorey(Name="Name")
tool.Ifc.link(element, obj)
bpy.data.collections.get("IfcBuilding/My Building").children.link(col)
col.objects.link(obj)
subject.sync(obj)
assert ifcopenshell.util.element.get_aggregate(element).is_a("IfcBuilding")
def test_openings_are_never_contained(self):
bpy.ops.bim.create_project()
obj = bpy.data.objects.new("Object", None)
element = tool.Ifc.get().createIfcOpeningElement()
tool.Ifc.link(element, obj)
bpy.data.collections.get("IfcSite/My Site").objects.link(obj)
subject.sync(obj)
assert ifcopenshell.util.element.get_container(element) is None