Fix bug where auto assignment in the collection hierarchy failed if you had filtered out aggregates and you were assigning a subelement of an aggregate

This commit is contained in:
Dion Moult
2021-10-20 19:56:46 +11:00
parent 503f0399ff
commit 575de12d79
2 changed files with 45 additions and 3 deletions
+4 -3
View File
@@ -82,9 +82,10 @@ class Collector(blenderbim.core.tool.Collector):
aggregate = ifcopenshell.util.element.get_aggregate(element)
if aggregate:
aggregate_obj = tool.Ifc.get_object(aggregate)
collection = bpy.data.collections.get(aggregate_obj.name)
if collection:
return collection
if aggregate_obj:
collection = bpy.data.collections.get(aggregate_obj.name)
if collection:
return collection
container = ifcopenshell.util.element.get_container(element)
if container:
@@ -117,3 +117,44 @@ class TestAssign(NewFile):
subject.assign(space_obj)
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
def test_in_decomposition_mode_aggregates_subelements_are_placed_in_the_aggregates_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,
product=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(),
product=element,
relating_structure=tool.Ifc.get().by_type("IfcSite")[0],
)
ifcopenshell.api.run(
"aggregate.assign_object",
tool.Ifc.get(),
relating_object=element,
product=subelement,
)
subject.assign(subelement_obj)
assert subelement_obj.users_collection[0].name == "IfcSite/My Site"