mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-09-20 23:36:20 +00:00
aggregate.assign_object - support batching #4474
This commit is contained in:
@@ -473,7 +473,7 @@ class AssignStructuralLoadCase(bpy.types.Operator, tool.Ifc.Operator):
|
|||||||
self.file,
|
self.file,
|
||||||
**{
|
**{
|
||||||
"relating_object": self.file.by_id(self.work_plan),
|
"relating_object": self.file.by_id(self.work_plan),
|
||||||
"product": self.file.by_id(self.load_case),
|
"products": [self.file.by_id(self.load_case)],
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
return {"FINISHED"}
|
return {"FINISHED"}
|
||||||
|
|||||||
@@ -29,7 +29,7 @@ def assign_object(ifc, aggregator, collector, relating_obj=None, related_obj=Non
|
|||||||
if not aggregator.can_aggregate(relating_obj, related_obj):
|
if not aggregator.can_aggregate(relating_obj, related_obj):
|
||||||
return
|
return
|
||||||
rel = ifc.run(
|
rel = ifc.run(
|
||||||
"aggregate.assign_object", product=ifc.get_entity(related_obj), relating_object=ifc.get_entity(relating_obj)
|
"aggregate.assign_object", products=[ifc.get_entity(related_obj)], relating_object=ifc.get_entity(relating_obj)
|
||||||
)
|
)
|
||||||
collector.assign(relating_obj)
|
collector.assign(relating_obj)
|
||||||
collector.assign(related_obj)
|
collector.assign(related_obj)
|
||||||
|
|||||||
@@ -61,7 +61,7 @@ def remove_work_schedule(ifc, work_schedule=None):
|
|||||||
|
|
||||||
def assign_work_schedule(ifc, work_plan=None, work_schedule=None):
|
def assign_work_schedule(ifc, work_plan=None, work_schedule=None):
|
||||||
if work_schedule:
|
if work_schedule:
|
||||||
return ifc.run("aggregate.assign_object", relating_object=work_plan, product=work_schedule)
|
return ifc.run("aggregate.assign_object", relating_object=work_plan, products=[work_schedule])
|
||||||
|
|
||||||
|
|
||||||
def unassign_work_schedule(ifc, work_schedule=None):
|
def unassign_work_schedule(ifc, work_schedule=None):
|
||||||
|
|||||||
@@ -127,9 +127,9 @@ class Obj2Ifc:
|
|||||||
self.storey = ifcopenshell.api.run(
|
self.storey = ifcopenshell.api.run(
|
||||||
"root.create_entity", self.file, ifc_class="IfcBuildingStorey", name="My Storey"
|
"root.create_entity", self.file, ifc_class="IfcBuildingStorey", name="My Storey"
|
||||||
)
|
)
|
||||||
ifcopenshell.api.run("aggregate.assign_object", self.file, product=site, relating_object=project)
|
ifcopenshell.api.run("aggregate.assign_object", self.file, products=[site], relating_object=project)
|
||||||
ifcopenshell.api.run("aggregate.assign_object", self.file, product=building, relating_object=site)
|
ifcopenshell.api.run("aggregate.assign_object", self.file, products=[building], relating_object=site)
|
||||||
ifcopenshell.api.run("aggregate.assign_object", self.file, product=self.storey, relating_object=building)
|
ifcopenshell.api.run("aggregate.assign_object", self.file, products=[self.storey], relating_object=building)
|
||||||
|
|
||||||
ifcopenshell.api.run("geometry.edit_object_placement", self.file, product=site)
|
ifcopenshell.api.run("geometry.edit_object_placement", self.file, product=site)
|
||||||
ifcopenshell.api.run("geometry.edit_object_placement", self.file, product=building)
|
ifcopenshell.api.run("geometry.edit_object_placement", self.file, product=building)
|
||||||
|
|||||||
@@ -120,9 +120,9 @@ class Obj2Ifc:
|
|||||||
self.storey = ifcopenshell.api.run(
|
self.storey = ifcopenshell.api.run(
|
||||||
"root.create_entity", self.file, ifc_class="IfcBuildingStorey", name="My Storey"
|
"root.create_entity", self.file, ifc_class="IfcBuildingStorey", name="My Storey"
|
||||||
)
|
)
|
||||||
ifcopenshell.api.run("aggregate.assign_object", self.file, product=site, relating_object=project)
|
ifcopenshell.api.run("aggregate.assign_object", self.file, products=[site], relating_object=project)
|
||||||
ifcopenshell.api.run("aggregate.assign_object", self.file, product=building, relating_object=site)
|
ifcopenshell.api.run("aggregate.assign_object", self.file, products=[building], relating_object=site)
|
||||||
ifcopenshell.api.run("aggregate.assign_object", self.file, product=self.storey, relating_object=building)
|
ifcopenshell.api.run("aggregate.assign_object", self.file, products=[self.storey], relating_object=building)
|
||||||
|
|
||||||
ifcopenshell.api.run("geometry.edit_object_placement", self.file, product=site)
|
ifcopenshell.api.run("geometry.edit_object_placement", self.file, product=site)
|
||||||
ifcopenshell.api.run("geometry.edit_object_placement", self.file, product=building)
|
ifcopenshell.api.run("geometry.edit_object_placement", self.file, product=building)
|
||||||
|
|||||||
@@ -38,7 +38,7 @@ class TestAssignObject:
|
|||||||
ifc.get_entity("relating_obj").should_be_called().will_return("relating_object")
|
ifc.get_entity("relating_obj").should_be_called().will_return("relating_object")
|
||||||
ifc.get_entity("related_obj").should_be_called().will_return("related_object")
|
ifc.get_entity("related_obj").should_be_called().will_return("related_object")
|
||||||
ifc.run(
|
ifc.run(
|
||||||
"aggregate.assign_object", product="related_object", relating_object="relating_object"
|
"aggregate.assign_object", products=["related_object"], relating_object="relating_object"
|
||||||
).should_be_called().will_return("rel")
|
).should_be_called().will_return("rel")
|
||||||
aggregate.disable_editing("related_obj").should_be_called()
|
aggregate.disable_editing("related_obj").should_be_called()
|
||||||
collector.assign("relating_obj").should_be_called()
|
collector.assign("relating_obj").should_be_called()
|
||||||
|
|||||||
@@ -320,8 +320,8 @@ class TestGetParentSpace(NewFile):
|
|||||||
element = ifcopenshell.api.run("root.create_entity", ifc, ifc_class="IfcBuildingStorey")
|
element = ifcopenshell.api.run("root.create_entity", ifc, ifc_class="IfcBuildingStorey")
|
||||||
subelement = ifcopenshell.api.run("root.create_entity", ifc, ifc_class="IfcSpace")
|
subelement = ifcopenshell.api.run("root.create_entity", ifc, ifc_class="IfcSpace")
|
||||||
project = ifcopenshell.api.run("root.create_entity", ifc, ifc_class="IfcProject")
|
project = ifcopenshell.api.run("root.create_entity", ifc, ifc_class="IfcProject")
|
||||||
ifcopenshell.api.run("aggregate.assign_object", ifc, product=subelement, relating_object=element)
|
ifcopenshell.api.run("aggregate.assign_object", ifc, products=[subelement], relating_object=element)
|
||||||
ifcopenshell.api.run("aggregate.assign_object", ifc, product=element, relating_object=project)
|
ifcopenshell.api.run("aggregate.assign_object", ifc, products=[element], relating_object=project)
|
||||||
assert subject.get_parent_space(subelement) == element
|
assert subject.get_parent_space(subelement) == element
|
||||||
assert subject.get_parent_space(element) is None
|
assert subject.get_parent_space(element) is None
|
||||||
|
|
||||||
|
|||||||
@@ -68,7 +68,7 @@ class TestAssign(NewFile):
|
|||||||
"aggregate.assign_object",
|
"aggregate.assign_object",
|
||||||
tool.Ifc.get(),
|
tool.Ifc.get(),
|
||||||
relating_object=tool.Ifc.get().by_type("IfcSite")[0],
|
relating_object=tool.Ifc.get().by_type("IfcSite")[0],
|
||||||
product=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) == 1
|
||||||
@@ -84,7 +84,7 @@ class TestAssign(NewFile):
|
|||||||
"aggregate.assign_object",
|
"aggregate.assign_object",
|
||||||
tool.Ifc.get(),
|
tool.Ifc.get(),
|
||||||
relating_object=tool.Ifc.get().by_type("IfcSite")[0],
|
relating_object=tool.Ifc.get().by_type("IfcSite")[0],
|
||||||
product=space_element,
|
products=[space_element],
|
||||||
)
|
)
|
||||||
subject.assign(space_obj)
|
subject.assign(space_obj)
|
||||||
subject.assign(space_obj)
|
subject.assign(space_obj)
|
||||||
@@ -103,7 +103,7 @@ class TestAssign(NewFile):
|
|||||||
"aggregate.assign_object",
|
"aggregate.assign_object",
|
||||||
tool.Ifc.get(),
|
tool.Ifc.get(),
|
||||||
relating_object=tool.Ifc.get().by_type("IfcSite")[0],
|
relating_object=tool.Ifc.get().by_type("IfcSite")[0],
|
||||||
product=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) == 1
|
||||||
@@ -121,7 +121,7 @@ class TestAssign(NewFile):
|
|||||||
"aggregate.assign_object",
|
"aggregate.assign_object",
|
||||||
tool.Ifc.get(),
|
tool.Ifc.get(),
|
||||||
relating_object=element,
|
relating_object=element,
|
||||||
product=subelement,
|
products=[subelement],
|
||||||
)
|
)
|
||||||
subject.assign(element_obj)
|
subject.assign(element_obj)
|
||||||
assert len(element_obj.users_collection) == 1
|
assert len(element_obj.users_collection) == 1
|
||||||
@@ -161,7 +161,7 @@ class TestAssign(NewFile):
|
|||||||
"aggregate.assign_object",
|
"aggregate.assign_object",
|
||||||
tool.Ifc.get(),
|
tool.Ifc.get(),
|
||||||
relating_object=tool.Ifc.get().by_type("IfcSite")[0],
|
relating_object=tool.Ifc.get().by_type("IfcSite")[0],
|
||||||
product=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
|
||||||
@@ -180,7 +180,7 @@ class TestAssign(NewFile):
|
|||||||
"aggregate.assign_object",
|
"aggregate.assign_object",
|
||||||
tool.Ifc.get(),
|
tool.Ifc.get(),
|
||||||
relating_object=element,
|
relating_object=element,
|
||||||
product=subelement,
|
products=[subelement],
|
||||||
)
|
)
|
||||||
subject.assign(element_obj)
|
subject.assign(element_obj)
|
||||||
subject.assign(subelement_obj)
|
subject.assign(subelement_obj)
|
||||||
@@ -203,7 +203,7 @@ class TestAssign(NewFile):
|
|||||||
"aggregate.assign_object",
|
"aggregate.assign_object",
|
||||||
tool.Ifc.get(),
|
tool.Ifc.get(),
|
||||||
relating_object=element,
|
relating_object=element,
|
||||||
product=subelement,
|
products=[subelement],
|
||||||
)
|
)
|
||||||
subject.assign(subelement_obj)
|
subject.assign(subelement_obj)
|
||||||
assert subelement_obj.users_collection[0].name == "IfcSite/My Site"
|
assert subelement_obj.users_collection[0].name == "IfcSite/My Site"
|
||||||
|
|||||||
@@ -86,8 +86,8 @@ class TestGetStoreyHeight(test.bim.bootstrap.NewFile):
|
|||||||
storey.Elevation = 3000
|
storey.Elevation = 3000
|
||||||
storey2 = ifc.createIfcBuildingStorey()
|
storey2 = ifc.createIfcBuildingStorey()
|
||||||
storey2.Elevation = 5000
|
storey2.Elevation = 5000
|
||||||
ifcopenshell.api.run("aggregate.assign_object", ifc, product=storey, relating_object=building)
|
ifcopenshell.api.run("aggregate.assign_object", ifc, products=[storey], relating_object=building)
|
||||||
ifcopenshell.api.run("aggregate.assign_object", ifc, product=storey2, relating_object=building)
|
ifcopenshell.api.run("aggregate.assign_object", ifc, products=[storey2], relating_object=building)
|
||||||
assert subject.get_storey_height_in_si(storey, 1) == 2.0
|
assert subject.get_storey_height_in_si(storey, 1) == 2.0
|
||||||
|
|
||||||
def test_getting_a_double_storey_height(self):
|
def test_getting_a_double_storey_height(self):
|
||||||
@@ -103,9 +103,9 @@ class TestGetStoreyHeight(test.bim.bootstrap.NewFile):
|
|||||||
storey2.Elevation = 5000
|
storey2.Elevation = 5000
|
||||||
storey3 = ifc.createIfcBuildingStorey()
|
storey3 = ifc.createIfcBuildingStorey()
|
||||||
storey3.Elevation = 9000
|
storey3.Elevation = 9000
|
||||||
ifcopenshell.api.run("aggregate.assign_object", ifc, product=storey, relating_object=building)
|
ifcopenshell.api.run("aggregate.assign_object", ifc, products=[storey], relating_object=building)
|
||||||
ifcopenshell.api.run("aggregate.assign_object", ifc, product=storey2, relating_object=building)
|
ifcopenshell.api.run("aggregate.assign_object", ifc, products=[storey2], relating_object=building)
|
||||||
ifcopenshell.api.run("aggregate.assign_object", ifc, product=storey3, relating_object=building)
|
ifcopenshell.api.run("aggregate.assign_object", ifc, products=[storey3], relating_object=building)
|
||||||
assert subject.get_storey_height_in_si(storey, 2) == 6.0
|
assert subject.get_storey_height_in_si(storey, 2) == 6.0
|
||||||
|
|
||||||
def test_only_considering_storeys_in_the_same_building(self):
|
def test_only_considering_storeys_in_the_same_building(self):
|
||||||
@@ -116,7 +116,7 @@ class TestGetStoreyHeight(test.bim.bootstrap.NewFile):
|
|||||||
storey.Elevation = 3000
|
storey.Elevation = 3000
|
||||||
storey2 = ifc.createIfcBuildingStorey()
|
storey2 = ifc.createIfcBuildingStorey()
|
||||||
storey2.Elevation = 5000
|
storey2.Elevation = 5000
|
||||||
ifcopenshell.api.run("aggregate.assign_object", ifc, product=storey, relating_object=building)
|
ifcopenshell.api.run("aggregate.assign_object", ifc, products=[storey], relating_object=building)
|
||||||
assert subject.get_storey_height_in_si(storey, 1) is None
|
assert subject.get_storey_height_in_si(storey, 1) is None
|
||||||
|
|
||||||
def test_returning_none_if_the_storey_height_is_undefined(self):
|
def test_returning_none_if_the_storey_height_is_undefined(self):
|
||||||
@@ -124,7 +124,7 @@ class TestGetStoreyHeight(test.bim.bootstrap.NewFile):
|
|||||||
tool.Ifc.set(ifc)
|
tool.Ifc.set(ifc)
|
||||||
building = ifc.createIfcBuilding()
|
building = ifc.createIfcBuilding()
|
||||||
storey = ifc.createIfcBuildingStorey()
|
storey = ifc.createIfcBuildingStorey()
|
||||||
ifcopenshell.api.run("aggregate.assign_object", ifc, product=storey, relating_object=building)
|
ifcopenshell.api.run("aggregate.assign_object", ifc, products=[storey], relating_object=building)
|
||||||
assert subject.get_storey_height_in_si(storey, 1) is None
|
assert subject.get_storey_height_in_si(storey, 1) is None
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -236,9 +236,9 @@ Create a simple model from scratch
|
|||||||
|
|
||||||
# Since the site is our top level location, assign it to the project
|
# Since the site is our top level location, assign it to the project
|
||||||
# Then place our building on the site, and our storey in the building
|
# Then place our building on the site, and our storey in the building
|
||||||
run("aggregate.assign_object", model, relating_object=project, product=site)
|
run("aggregate.assign_object", model, relating_object=project, products=[site])
|
||||||
run("aggregate.assign_object", model, relating_object=site, product=building)
|
run("aggregate.assign_object", model, relating_object=site, products=[building])
|
||||||
run("aggregate.assign_object", model, relating_object=building, product=storey)
|
run("aggregate.assign_object", model, relating_object=building, products=[storey])
|
||||||
|
|
||||||
# Let's create a new wall
|
# Let's create a new wall
|
||||||
wall = run("root.create_entity", model, ifc_class="IfcWall")
|
wall = run("root.create_entity", model, ifc_class="IfcWall")
|
||||||
|
|||||||
@@ -50,6 +50,7 @@ ARGUMENTS_DEPRECATION = {
|
|||||||
batching_argument_deprecation, prev_argument="product", new_argument="products"
|
batching_argument_deprecation, prev_argument="product", new_argument="products"
|
||||||
),
|
),
|
||||||
"group.unassign_group": partial(batching_argument_deprecation, prev_argument="product", new_argument="products"),
|
"group.unassign_group": partial(batching_argument_deprecation, prev_argument="product", new_argument="products"),
|
||||||
|
"aggregate.assign_object": partial(batching_argument_deprecation, prev_argument="product", new_argument="products"),
|
||||||
"layer.assign_layer": partial(batching_argument_deprecation, prev_argument="item", new_argument="items"),
|
"layer.assign_layer": partial(batching_argument_deprecation, prev_argument="item", new_argument="items"),
|
||||||
"layer.unassign_layer": partial(batching_argument_deprecation, prev_argument="item", new_argument="items"),
|
"layer.unassign_layer": partial(batching_argument_deprecation, prev_argument="item", new_argument="items"),
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -20,11 +20,17 @@ import ifcopenshell
|
|||||||
import ifcopenshell.api
|
import ifcopenshell.api
|
||||||
import ifcopenshell.util.element
|
import ifcopenshell.util.element
|
||||||
import ifcopenshell.util.placement
|
import ifcopenshell.util.placement
|
||||||
|
from typing import Union
|
||||||
|
|
||||||
|
|
||||||
class Usecase:
|
class Usecase:
|
||||||
def __init__(self, file, product=None, relating_object=None):
|
def __init__(
|
||||||
"""Assigns an object as an aggregate to a product
|
self,
|
||||||
|
file: ifcopenshell.file,
|
||||||
|
products: list[ifcopenshell.entity_instance],
|
||||||
|
relating_object: ifcopenshell.entity_instance,
|
||||||
|
):
|
||||||
|
"""Assigns object as an aggregate to the products
|
||||||
|
|
||||||
All physical IFC model elements must be part of a hierarchical tree
|
All physical IFC model elements must be part of a hierarchical tree
|
||||||
called the "spatial decomposition", where large things are made up of
|
called the "spatial decomposition", where large things are made up of
|
||||||
@@ -55,14 +61,15 @@ class Usecase:
|
|||||||
its parent in the spatial hierarchy. If your product has a placement,
|
its parent in the spatial hierarchy. If your product has a placement,
|
||||||
its placement will be recalculated to follow this convention.
|
its placement will be recalculated to follow this convention.
|
||||||
|
|
||||||
:param product: The part of the aggregate, typically an IfcElement or
|
:param products: The list of parts of the aggregate, typically of IfcElement or
|
||||||
IfcSpatialStructureElement subclass
|
IfcSpatialStructureElement subclass
|
||||||
:type product: ifcopenshell.entity_instance.entity_instance
|
:type product: list[ifcopenshell.entity_instance.entity_instance]
|
||||||
:param relating_object: The whole of the aggregate, typically an
|
:param relating_object: The whole of the aggregate, typically an
|
||||||
IfcElement or IfcSpatialStructureElement subclass
|
IfcElement or IfcSpatialStructureElement subclass
|
||||||
:type relating_object: ifcopenshell.entity_instance.entity_instance
|
:type relating_object: ifcopenshell.entity_instance.entity_instance
|
||||||
:return: The IfcRelAggregate relationship instance
|
:return: The IfcRelAggregate relationship instance
|
||||||
:rtype: ifcopenshell.entity_instance.entity_instance
|
or `None` if `products` was empty list.
|
||||||
|
:rtype: Union[ifcopenshell.entity_instance.entity_instance, None]
|
||||||
|
|
||||||
Example:
|
Example:
|
||||||
|
|
||||||
@@ -73,40 +80,59 @@ class Usecase:
|
|||||||
subelement = ifcopenshell.api.run("root.create_entity", model, ifc_class="IfcBuilding")
|
subelement = ifcopenshell.api.run("root.create_entity", model, ifc_class="IfcBuilding")
|
||||||
|
|
||||||
# The project contains a site (note that project aggregation is a special case in IFC)
|
# The project contains a site (note that project aggregation is a special case in IFC)
|
||||||
ifcopenshell.api.run("aggregate.assign_object", model, product=element, relating_object=project)
|
ifcopenshell.api.run("aggregate.assign_object", model, products=[element], relating_object=project)
|
||||||
|
|
||||||
# The site has a building
|
# The site has a building
|
||||||
ifcopenshell.api.run("aggregate.assign_object", model, product=subelement, relating_object=element)
|
ifcopenshell.api.run("aggregate.assign_object", model, products=[subelement], relating_object=element)
|
||||||
"""
|
"""
|
||||||
self.file = file
|
self.file = file
|
||||||
self.settings = {
|
self.settings = {
|
||||||
"product": product,
|
"products": products,
|
||||||
"relating_object": relating_object,
|
"relating_object": relating_object,
|
||||||
}
|
}
|
||||||
|
|
||||||
def execute(self):
|
def execute(self) -> Union[ifcopenshell.entity_instance, None]:
|
||||||
decomposes = None
|
if not self.settings["products"]:
|
||||||
if self.settings["product"].Decomposes:
|
return
|
||||||
decomposes = self.settings["product"].Decomposes[0]
|
|
||||||
|
|
||||||
is_decomposed_by = None
|
products = set(self.settings["products"])
|
||||||
for rel in self.settings["relating_object"].IsDecomposedBy:
|
relating_object = self.settings["relating_object"]
|
||||||
if rel.is_a("IfcRelAggregates"):
|
is_decomposed_by = next((i for i in relating_object.IsDecomposedBy if i.is_a("IfcRelAggregates")), None)
|
||||||
is_decomposed_by = rel
|
|
||||||
break
|
|
||||||
|
|
||||||
if decomposes and decomposes == is_decomposed_by:
|
previous_aggregates_rels: set[ifcopenshell.entity_instance] = set()
|
||||||
return decomposes
|
products_without_aggregates: list[ifcopenshell.entity_instance] = []
|
||||||
|
products_with_aggregates: list[ifcopenshell.entity_instance] = []
|
||||||
|
|
||||||
container = ifcopenshell.util.element.get_container(self.settings["product"], should_get_direct=True)
|
# check if there is anything to change
|
||||||
if container:
|
for product in products:
|
||||||
ifcopenshell.api.run("spatial.remove_container", self.file, product=self.settings["product"])
|
product_rel = next(iter(product.Decomposes), None)
|
||||||
|
|
||||||
if decomposes:
|
if product_rel is None:
|
||||||
related_objects = list(decomposes.RelatedObjects)
|
products_without_aggregates.append(product)
|
||||||
related_objects.remove(self.settings["product"])
|
continue
|
||||||
|
|
||||||
|
# either is_decomposed_by is None or product is part of different rel
|
||||||
|
if product_rel != is_decomposed_by:
|
||||||
|
previous_aggregates_rels.add(product_rel)
|
||||||
|
products_with_aggregates.append(product)
|
||||||
|
|
||||||
|
# products with already assigned aggregates will be skipped
|
||||||
|
|
||||||
|
products_to_change = products_without_aggregates + products_with_aggregates
|
||||||
|
# nothing to change
|
||||||
|
if not products_to_change:
|
||||||
|
return is_decomposed_by
|
||||||
|
|
||||||
|
# can be either only aggregated or only contained at the same time
|
||||||
|
# some product might not be able to have a container
|
||||||
|
possibly_contained_products = [p for p in products_without_aggregates if hasattr(p, "ContainedInStructure")]
|
||||||
|
ifcopenshell.api.run("spatial.unassign_container", self.file, products=possibly_contained_products)
|
||||||
|
|
||||||
|
# unassign elements from previous aggregates
|
||||||
|
for decomposes in previous_aggregates_rels:
|
||||||
|
related_objects = set(decomposes.RelatedObjects) - products
|
||||||
if related_objects:
|
if related_objects:
|
||||||
decomposes.RelatedObjects = related_objects
|
decomposes.RelatedObjects = list(related_objects)
|
||||||
ifcopenshell.api.run("owner.update_owner_history", self.file, **{"element": decomposes})
|
ifcopenshell.api.run("owner.update_owner_history", self.file, **{"element": decomposes})
|
||||||
else:
|
else:
|
||||||
history = decomposes.OwnerHistory
|
history = decomposes.OwnerHistory
|
||||||
@@ -114,10 +140,9 @@ class Usecase:
|
|||||||
if history:
|
if history:
|
||||||
ifcopenshell.util.element.remove_deep2(self.file, history)
|
ifcopenshell.util.element.remove_deep2(self.file, history)
|
||||||
|
|
||||||
|
# assign elements to a new aggregate
|
||||||
if is_decomposed_by:
|
if is_decomposed_by:
|
||||||
related_objects = set(is_decomposed_by.RelatedObjects)
|
is_decomposed_by.RelatedObjects = list(set(is_decomposed_by.RelatedObjects) | products)
|
||||||
related_objects.add(self.settings["product"])
|
|
||||||
is_decomposed_by.RelatedObjects = list(related_objects)
|
|
||||||
ifcopenshell.api.run("owner.update_owner_history", self.file, **{"element": is_decomposed_by})
|
ifcopenshell.api.run("owner.update_owner_history", self.file, **{"element": is_decomposed_by})
|
||||||
else:
|
else:
|
||||||
is_decomposed_by = self.file.create_entity(
|
is_decomposed_by = self.file.create_entity(
|
||||||
@@ -125,19 +150,21 @@ class Usecase:
|
|||||||
**{
|
**{
|
||||||
"GlobalId": ifcopenshell.guid.new(),
|
"GlobalId": ifcopenshell.guid.new(),
|
||||||
"OwnerHistory": ifcopenshell.api.run("owner.create_owner_history", self.file),
|
"OwnerHistory": ifcopenshell.api.run("owner.create_owner_history", self.file),
|
||||||
"RelatedObjects": [self.settings["product"]],
|
"RelatedObjects": list(products),
|
||||||
"RelatingObject": self.settings["relating_object"],
|
"RelatingObject": relating_object,
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
placement = getattr(self.settings["product"], "ObjectPlacement", None)
|
# localize placement relative to a new aggregate for affected products
|
||||||
if placement and placement.is_a("IfcLocalPlacement"):
|
for product in products_to_change:
|
||||||
ifcopenshell.api.run(
|
placement = getattr(product, "ObjectPlacement", None)
|
||||||
"geometry.edit_object_placement",
|
if placement and placement.is_a("IfcLocalPlacement"):
|
||||||
self.file,
|
ifcopenshell.api.run(
|
||||||
product=self.settings["product"],
|
"geometry.edit_object_placement",
|
||||||
matrix=ifcopenshell.util.placement.get_local_placement(self.settings["product"].ObjectPlacement),
|
self.file,
|
||||||
is_si=False,
|
product=product,
|
||||||
)
|
matrix=ifcopenshell.util.placement.get_local_placement(product.ObjectPlacement),
|
||||||
|
is_si=False,
|
||||||
|
)
|
||||||
|
|
||||||
return is_decomposed_by
|
return is_decomposed_by
|
||||||
|
|||||||
@@ -51,8 +51,8 @@ class Usecase:
|
|||||||
element = ifcopenshell.api.run("root.create_entity", model, ifc_class="IfcSite")
|
element = ifcopenshell.api.run("root.create_entity", model, ifc_class="IfcSite")
|
||||||
subelement1 = ifcopenshell.api.run("root.create_entity", model, ifc_class="IfcBuilding")
|
subelement1 = ifcopenshell.api.run("root.create_entity", model, ifc_class="IfcBuilding")
|
||||||
subelement2 = ifcopenshell.api.run("root.create_entity", model, ifc_class="IfcBuilding")
|
subelement2 = ifcopenshell.api.run("root.create_entity", model, ifc_class="IfcBuilding")
|
||||||
ifcopenshell.api.run("aggregate.assign_object", model, product=subelement1, relating_object=element)
|
ifcopenshell.api.run("aggregate.assign_object", model, products=[subelement1], relating_object=element)
|
||||||
ifcopenshell.api.run("aggregate.assign_object", model, product=subelement2, relating_object=element)
|
ifcopenshell.api.run("aggregate.assign_object", model, products=[subelement2], relating_object=element)
|
||||||
# The relationship is returned as element still has subelement2
|
# The relationship is returned as element still has subelement2
|
||||||
rel = ifcopenshell.api.run("aggregate.unassign_object", model, product=subelement1)
|
rel = ifcopenshell.api.run("aggregate.unassign_object", model, product=subelement1)
|
||||||
# Nothing is returned, as element is now empty
|
# Nothing is returned, as element is now empty
|
||||||
|
|||||||
@@ -107,7 +107,7 @@ class Usecase:
|
|||||||
"aggregate.assign_object",
|
"aggregate.assign_object",
|
||||||
self.file,
|
self.file,
|
||||||
**{
|
**{
|
||||||
"product": work_schedule,
|
"products": [work_schedule],
|
||||||
"relating_object": self.settings["work_plan"],
|
"relating_object": self.settings["work_plan"],
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -64,7 +64,7 @@ class Usecase:
|
|||||||
"aggregate.assign_object",
|
"aggregate.assign_object",
|
||||||
self.file,
|
self.file,
|
||||||
**{
|
**{
|
||||||
"product": self.settings["work_schedule"],
|
"products": [self.settings["work_schedule"]],
|
||||||
"relating_object": self.settings["work_plan"],
|
"relating_object": self.settings["work_plan"],
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -73,7 +73,7 @@ class Usecase:
|
|||||||
as IfcBuilding, IfcBuildingStorey, or IfcSpace that the element
|
as IfcBuilding, IfcBuildingStorey, or IfcSpace that the element
|
||||||
exists in.
|
exists in.
|
||||||
:return: The IfcRelContainedInSpatialStructure relationship instance
|
:return: The IfcRelContainedInSpatialStructure relationship instance
|
||||||
or `None` if nothing was changed.
|
or `None` if `products` was empty list.
|
||||||
:rtype: Union[ifcopenshell.entity_instance.entity_instance, None]
|
:rtype: Union[ifcopenshell.entity_instance.entity_instance, None]
|
||||||
|
|
||||||
Example:
|
Example:
|
||||||
@@ -128,13 +128,17 @@ class Usecase:
|
|||||||
products_without_containers.append(product)
|
products_without_containers.append(product)
|
||||||
continue
|
continue
|
||||||
|
|
||||||
|
# either structure_rel is None or product is part of different rel
|
||||||
if product_rel != structure_rel:
|
if product_rel != structure_rel:
|
||||||
previous_containers_rels.add(product_rel)
|
previous_containers_rels.add(product_rel)
|
||||||
products_with_containers.append(product)
|
products_with_containers.append(product)
|
||||||
|
|
||||||
|
# products with already assigned containers will be skipped
|
||||||
|
|
||||||
|
products_to_change = products_without_containers + products_with_containers
|
||||||
# nothing to change
|
# nothing to change
|
||||||
if not products_without_containers and not products_with_containers:
|
if not products_to_change:
|
||||||
return
|
return structure_rel
|
||||||
|
|
||||||
# can be either only aggregated or only contained at the same time
|
# can be either only aggregated or only contained at the same time
|
||||||
for product in products_without_containers:
|
for product in products_without_containers:
|
||||||
@@ -142,7 +146,7 @@ class Usecase:
|
|||||||
if aggregate:
|
if aggregate:
|
||||||
ifcopenshell.api.run("aggregate.unassign_object", self.file, product=product)
|
ifcopenshell.api.run("aggregate.unassign_object", self.file, product=product)
|
||||||
|
|
||||||
# unassign elements from previous container
|
# unassign elements from previous containers
|
||||||
for rel in previous_containers_rels:
|
for rel in previous_containers_rels:
|
||||||
related_elements = set(rel.RelatedElements) - products
|
related_elements = set(rel.RelatedElements) - products
|
||||||
if related_elements:
|
if related_elements:
|
||||||
@@ -170,7 +174,7 @@ class Usecase:
|
|||||||
)
|
)
|
||||||
|
|
||||||
# localize placement relative to a new container for affected products
|
# localize placement relative to a new container for affected products
|
||||||
for product in products_without_containers + products_with_containers:
|
for product in products_to_change:
|
||||||
placement = getattr(product, "ObjectPlacement", None)
|
placement = getattr(product, "ObjectPlacement", None)
|
||||||
if placement and placement.is_a("IfcLocalPlacement"):
|
if placement and placement.is_a("IfcLocalPlacement"):
|
||||||
ifcopenshell.api.run(
|
ifcopenshell.api.run(
|
||||||
|
|||||||
@@ -45,12 +45,12 @@ class Usecase:
|
|||||||
storey3 = ifcopenshell.api.run("root.create_entity", model, ifc_class="IfcBuildingStorey")
|
storey3 = ifcopenshell.api.run("root.create_entity", model, ifc_class="IfcBuildingStorey")
|
||||||
|
|
||||||
# The project contains a site (note that project aggregation is a special case in IFC)
|
# The project contains a site (note that project aggregation is a special case in IFC)
|
||||||
ifcopenshell.api.run("aggregate.assign_object", model, product=site, relating_object=project)
|
ifcopenshell.api.run("aggregate.assign_object", model, products=[site], relating_object=project)
|
||||||
|
|
||||||
# The site has a building, the building has a storey, and the storey has a space
|
# The site has a building, the building has a storey, and the storey has a space
|
||||||
ifcopenshell.api.run("aggregate.assign_object", model, product=building, relating_object=site)
|
ifcopenshell.api.run("aggregate.assign_object", model, products=[building], relating_object=site)
|
||||||
ifcopenshell.api.run("aggregate.assign_object", model, product=storey, relating_object=building)
|
ifcopenshell.api.run("aggregate.assign_object", model, products=[storey], relating_object=building)
|
||||||
ifcopenshell.api.run("aggregate.assign_object", model, product=space, relating_object=storey)
|
ifcopenshell.api.run("aggregate.assign_object", model, products=[space], relating_object=storey)
|
||||||
|
|
||||||
# Create a column, this column spans 3 storeys
|
# Create a column, this column spans 3 storeys
|
||||||
column = ifcopenshell.api.run("root.create_entity", model, ifc_class="IfcWall")
|
column = ifcopenshell.api.run("root.create_entity", model, ifc_class="IfcWall")
|
||||||
|
|||||||
@@ -59,12 +59,12 @@ class Usecase:
|
|||||||
storey3 = ifcopenshell.api.run("root.create_entity", model, ifc_class="IfcBuildingStorey")
|
storey3 = ifcopenshell.api.run("root.create_entity", model, ifc_class="IfcBuildingStorey")
|
||||||
|
|
||||||
# The project contains a site (note that project aggregation is a special case in IFC)
|
# The project contains a site (note that project aggregation is a special case in IFC)
|
||||||
ifcopenshell.api.run("aggregate.assign_object", model, product=site, relating_object=project)
|
ifcopenshell.api.run("aggregate.assign_object", model, products=[site], relating_object=project)
|
||||||
|
|
||||||
# The site has a building, the building has a storey, and the storey has a space
|
# The site has a building, the building has a storey, and the storey has a space
|
||||||
ifcopenshell.api.run("aggregate.assign_object", model, product=building, relating_object=site)
|
ifcopenshell.api.run("aggregate.assign_object", model, products=[building], relating_object=site)
|
||||||
ifcopenshell.api.run("aggregate.assign_object", model, product=storey, relating_object=building)
|
ifcopenshell.api.run("aggregate.assign_object", model, products=[storey], relating_object=building)
|
||||||
ifcopenshell.api.run("aggregate.assign_object", model, product=space, relating_object=storey)
|
ifcopenshell.api.run("aggregate.assign_object", model, products=[space], relating_object=storey)
|
||||||
|
|
||||||
# Create a column, this column spans 3 storeys
|
# Create a column, this column spans 3 storeys
|
||||||
column = ifcopenshell.api.run("root.create_entity", model, ifc_class="IfcWall")
|
column = ifcopenshell.api.run("root.create_entity", model, ifc_class="IfcWall")
|
||||||
|
|||||||
@@ -42,11 +42,11 @@ class Usecase:
|
|||||||
storey = ifcopenshell.api.run("root.create_entity", model, ifc_class="IfcBuildingStorey")
|
storey = ifcopenshell.api.run("root.create_entity", model, ifc_class="IfcBuildingStorey")
|
||||||
|
|
||||||
# The project contains a site (note that project aggregation is a special case in IFC)
|
# The project contains a site (note that project aggregation is a special case in IFC)
|
||||||
ifcopenshell.api.run("aggregate.assign_object", model, product=site, relating_object=project)
|
ifcopenshell.api.run("aggregate.assign_object", model, products=[site], relating_object=project)
|
||||||
|
|
||||||
# The site has a building, the building has a storey, and the storey has a space
|
# The site has a building, the building has a storey, and the storey has a space
|
||||||
ifcopenshell.api.run("aggregate.assign_object", model, product=building, relating_object=site)
|
ifcopenshell.api.run("aggregate.assign_object", model, products=[building], relating_object=site)
|
||||||
ifcopenshell.api.run("aggregate.assign_object", model, product=storey, relating_object=building)
|
ifcopenshell.api.run("aggregate.assign_object", model, products=[storey], relating_object=building)
|
||||||
|
|
||||||
# Create a wall
|
# Create a wall
|
||||||
wall = ifcopenshell.api.run("root.create_entity", model, ifc_class="IfcWall")
|
wall = ifcopenshell.api.run("root.create_entity", model, ifc_class="IfcWall")
|
||||||
|
|||||||
@@ -25,19 +25,23 @@ import ifcopenshell.util.placement
|
|||||||
|
|
||||||
|
|
||||||
class TestAssignObject(test.bootstrap.IFC4):
|
class TestAssignObject(test.bootstrap.IFC4):
|
||||||
def test_assigning_a_container(self):
|
def test_assigning_an_aggregate(self):
|
||||||
element = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcSite")
|
element = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcSite")
|
||||||
subelement = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcBuilding")
|
subelement1 = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcBuilding")
|
||||||
rel = ifcopenshell.api.run("aggregate.assign_object", self.file, product=subelement, relating_object=element)
|
subelement2 = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcBuilding")
|
||||||
assert ifcopenshell.util.element.get_aggregate(subelement) == element
|
rel = ifcopenshell.api.run(
|
||||||
|
"aggregate.assign_object", self.file, products=[subelement1, subelement2], relating_object=element
|
||||||
|
)
|
||||||
|
assert ifcopenshell.util.element.get_aggregate(subelement1) == element
|
||||||
|
assert ifcopenshell.util.element.get_aggregate(subelement2) == element
|
||||||
assert rel.is_a("IfcRelAggregates")
|
assert rel.is_a("IfcRelAggregates")
|
||||||
|
|
||||||
def test_doing_nothing_if_the_aggregate_is_already_assigned(self):
|
def test_doing_nothing_if_the_aggregate_is_already_assigned(self):
|
||||||
element = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcSite")
|
element = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcSite")
|
||||||
subelement = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcBuilding")
|
subelement = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcBuilding")
|
||||||
ifcopenshell.api.run("aggregate.assign_object", self.file, product=subelement, relating_object=element)
|
ifcopenshell.api.run("aggregate.assign_object", self.file, products=[subelement], relating_object=element)
|
||||||
total_elements = len([e for e in self.file])
|
total_elements = len([e for e in self.file])
|
||||||
ifcopenshell.api.run("aggregate.assign_object", self.file, product=subelement, relating_object=element)
|
ifcopenshell.api.run("aggregate.assign_object", self.file, products=[subelement], relating_object=element)
|
||||||
assert len([e for e in self.file]) == total_elements
|
assert len([e for e in self.file]) == total_elements
|
||||||
|
|
||||||
def test_that_old_aggregate_relationships_are_updated_if_they_still_have_elements(self):
|
def test_that_old_aggregate_relationships_are_updated_if_they_still_have_elements(self):
|
||||||
@@ -45,20 +49,20 @@ class TestAssignObject(test.bootstrap.IFC4):
|
|||||||
element2 = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcSite")
|
element2 = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcSite")
|
||||||
subelement1 = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcBuilding")
|
subelement1 = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcBuilding")
|
||||||
subelement2 = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcBuilding")
|
subelement2 = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcBuilding")
|
||||||
ifcopenshell.api.run("aggregate.assign_object", self.file, product=subelement1, relating_object=element1)
|
ifcopenshell.api.run("aggregate.assign_object", self.file, products=[subelement1], relating_object=element1)
|
||||||
ifcopenshell.api.run("aggregate.assign_object", self.file, product=subelement2, relating_object=element1)
|
ifcopenshell.api.run("aggregate.assign_object", self.file, products=[subelement2], relating_object=element1)
|
||||||
rel = subelement1.Decomposes[0]
|
rel = subelement1.Decomposes[0]
|
||||||
assert len(rel.RelatedObjects) == 2
|
assert len(rel.RelatedObjects) == 2
|
||||||
ifcopenshell.api.run("aggregate.assign_object", self.file, product=subelement1, relating_object=element2)
|
ifcopenshell.api.run("aggregate.assign_object", self.file, products=[subelement1], relating_object=element2)
|
||||||
assert len(rel.RelatedObjects) == 1
|
assert len(rel.RelatedObjects) == 1
|
||||||
|
|
||||||
def test_that_old_aggregate_relationships_are_purged_if_no_more_elements_are_contained(self):
|
def test_that_old_aggregate_relationships_are_purged_if_no_more_elements_are_contained(self):
|
||||||
element1 = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcSite")
|
element1 = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcSite")
|
||||||
element2 = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcSite")
|
element2 = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcSite")
|
||||||
subelement1 = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcBuilding")
|
subelement1 = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcBuilding")
|
||||||
ifcopenshell.api.run("aggregate.assign_object", self.file, product=subelement1, relating_object=element1)
|
ifcopenshell.api.run("aggregate.assign_object", self.file, products=[subelement1], relating_object=element1)
|
||||||
rel_id = subelement1.Decomposes[0].id()
|
rel_id = subelement1.Decomposes[0].id()
|
||||||
ifcopenshell.api.run("aggregate.assign_object", self.file, product=subelement1, relating_object=element2)
|
ifcopenshell.api.run("aggregate.assign_object", self.file, products=[subelement1], relating_object=element2)
|
||||||
with pytest.raises(RuntimeError):
|
with pytest.raises(RuntimeError):
|
||||||
self.file.by_id(rel_id)
|
self.file.by_id(rel_id)
|
||||||
|
|
||||||
@@ -68,7 +72,7 @@ class TestAssignObject(test.bootstrap.IFC4):
|
|||||||
element1 = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcSite")
|
element1 = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcSite")
|
||||||
element2 = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcSite")
|
element2 = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcSite")
|
||||||
subelement = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcBuilding")
|
subelement = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcBuilding")
|
||||||
ifcopenshell.api.run("aggregate.assign_object", self.file, product=subelement, relating_object=element1)
|
ifcopenshell.api.run("aggregate.assign_object", self.file, products=[subelement], relating_object=element1)
|
||||||
matrix1 = numpy.array(
|
matrix1 = numpy.array(
|
||||||
(
|
(
|
||||||
(1.0, 0.0, 0.0, 1.0),
|
(1.0, 0.0, 0.0, 1.0),
|
||||||
@@ -94,7 +98,7 @@ class TestAssignObject(test.bootstrap.IFC4):
|
|||||||
ifcopenshell.api.run(
|
ifcopenshell.api.run(
|
||||||
"geometry.edit_object_placement", self.file, product=subelement, matrix=matrix1.copy(), is_si=False
|
"geometry.edit_object_placement", self.file, product=subelement, matrix=matrix1.copy(), is_si=False
|
||||||
)
|
)
|
||||||
ifcopenshell.api.run("aggregate.assign_object", self.file, product=subelement, relating_object=element2)
|
ifcopenshell.api.run("aggregate.assign_object", self.file, products=[subelement], relating_object=element2)
|
||||||
assert subelement.ObjectPlacement.PlacementRelTo.PlacesObject[0] == element2
|
assert subelement.ObjectPlacement.PlacementRelTo.PlacesObject[0] == element2
|
||||||
assert numpy.array_equal(ifcopenshell.util.placement.get_local_placement(subelement.ObjectPlacement), matrix1)
|
assert numpy.array_equal(ifcopenshell.util.placement.get_local_placement(subelement.ObjectPlacement), matrix1)
|
||||||
|
|
||||||
@@ -105,7 +109,7 @@ class TestAssignObject(test.bootstrap.IFC4):
|
|||||||
subelement = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcBuilding")
|
subelement = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcBuilding")
|
||||||
placement = self.file.createIfcGridPlacement()
|
placement = self.file.createIfcGridPlacement()
|
||||||
subelement.ObjectPlacement = placement
|
subelement.ObjectPlacement = placement
|
||||||
ifcopenshell.api.run("aggregate.assign_object", self.file, product=subelement, relating_object=element)
|
ifcopenshell.api.run("aggregate.assign_object", self.file, products=[subelement], relating_object=element)
|
||||||
assert subelement.ObjectPlacement == placement
|
assert subelement.ObjectPlacement == placement
|
||||||
|
|
||||||
def test_removing_containment_if_it_exists(self):
|
def test_removing_containment_if_it_exists(self):
|
||||||
@@ -115,5 +119,5 @@ class TestAssignObject(test.bootstrap.IFC4):
|
|||||||
container = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcBuildingStorey")
|
container = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcBuildingStorey")
|
||||||
subelement = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWall")
|
subelement = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWall")
|
||||||
ifcopenshell.api.run("spatial.assign_container", self.file, products=[subelement], relating_structure=container)
|
ifcopenshell.api.run("spatial.assign_container", self.file, products=[subelement], relating_structure=container)
|
||||||
ifcopenshell.api.run("aggregate.assign_object", self.file, product=subelement, relating_object=element)
|
ifcopenshell.api.run("aggregate.assign_object", self.file, products=[subelement], relating_object=element)
|
||||||
assert not ifcopenshell.util.element.get_container(subelement, should_get_direct=True)
|
assert not ifcopenshell.util.element.get_container(subelement, should_get_direct=True)
|
||||||
|
|||||||
@@ -26,7 +26,7 @@ class TestUnassignObject(test.bootstrap.IFC4):
|
|||||||
def test_unassigning_an_object(self):
|
def test_unassigning_an_object(self):
|
||||||
element = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcSite")
|
element = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcSite")
|
||||||
subelement = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcBuilding")
|
subelement = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcBuilding")
|
||||||
ifcopenshell.api.run("aggregate.assign_object", self.file, product=subelement, relating_object=element)
|
ifcopenshell.api.run("aggregate.assign_object", self.file, products=[subelement], relating_object=element)
|
||||||
ifcopenshell.api.run("aggregate.unassign_object", self.file, product=subelement)
|
ifcopenshell.api.run("aggregate.unassign_object", self.file, product=subelement)
|
||||||
assert ifcopenshell.util.element.get_aggregate(subelement) is None
|
assert ifcopenshell.util.element.get_aggregate(subelement) is None
|
||||||
|
|
||||||
@@ -34,14 +34,14 @@ class TestUnassignObject(test.bootstrap.IFC4):
|
|||||||
element = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcSite")
|
element = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcSite")
|
||||||
subelement2 = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcBuilding")
|
subelement2 = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcBuilding")
|
||||||
subelement1 = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcBuilding")
|
subelement1 = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcBuilding")
|
||||||
ifcopenshell.api.run("aggregate.assign_object", self.file, product=subelement1, relating_object=element)
|
ifcopenshell.api.run("aggregate.assign_object", self.file, products=[subelement1], relating_object=element)
|
||||||
ifcopenshell.api.run("aggregate.assign_object", self.file, product=subelement2, relating_object=element)
|
ifcopenshell.api.run("aggregate.assign_object", self.file, products=[subelement2], relating_object=element)
|
||||||
ifcopenshell.api.run("aggregate.unassign_object", self.file, product=subelement1)
|
ifcopenshell.api.run("aggregate.unassign_object", self.file, product=subelement1)
|
||||||
assert len(self.file.by_type("IfcRelAggregates")) == 1
|
assert len(self.file.by_type("IfcRelAggregates")) == 1
|
||||||
|
|
||||||
def test_the_rel_is_purged_if_there_are_no_more_decomposed_elements(self):
|
def test_the_rel_is_purged_if_there_are_no_more_decomposed_elements(self):
|
||||||
element = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcSite")
|
element = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcSite")
|
||||||
subelement = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcBuilding")
|
subelement = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcBuilding")
|
||||||
ifcopenshell.api.run("aggregate.assign_object", self.file, product=subelement, relating_object=element)
|
ifcopenshell.api.run("aggregate.assign_object", self.file, products=[subelement], relating_object=element)
|
||||||
ifcopenshell.api.run("aggregate.unassign_object", self.file, product=subelement)
|
ifcopenshell.api.run("aggregate.unassign_object", self.file, product=subelement)
|
||||||
assert len(self.file.by_type("IfcRelAggregates")) == 0
|
assert len(self.file.by_type("IfcRelAggregates")) == 0
|
||||||
|
|||||||
@@ -253,7 +253,7 @@ class TestEditObjectPlacement(test.bootstrap.IFC4):
|
|||||||
(0.0, 0.0, 0.0, 1.0),
|
(0.0, 0.0, 0.0, 1.0),
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
ifcopenshell.api.run("aggregate.assign_object", self.file, product=subelement, relating_object=element)
|
ifcopenshell.api.run("aggregate.assign_object", self.file, products=[subelement], relating_object=element)
|
||||||
ifcopenshell.api.run(
|
ifcopenshell.api.run(
|
||||||
"geometry.edit_object_placement", self.file, product=element, matrix=matrix.copy(), is_si=False
|
"geometry.edit_object_placement", self.file, product=element, matrix=matrix.copy(), is_si=False
|
||||||
)
|
)
|
||||||
@@ -629,7 +629,7 @@ class TestEditObjectPlacement(test.bootstrap.IFC4):
|
|||||||
|
|
||||||
building = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcBuilding")
|
building = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcBuilding")
|
||||||
storey = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcBuildingStorey")
|
storey = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcBuildingStorey")
|
||||||
ifcopenshell.api.run("aggregate.assign_object", self.file, product=storey, relating_object=building)
|
ifcopenshell.api.run("aggregate.assign_object", self.file, products=[storey], relating_object=building)
|
||||||
wall = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWall")
|
wall = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWall")
|
||||||
ifcopenshell.api.run("spatial.assign_container", self.file, products=[wall], relating_structure=storey)
|
ifcopenshell.api.run("spatial.assign_container", self.file, products=[wall], relating_structure=storey)
|
||||||
|
|
||||||
|
|||||||
@@ -89,7 +89,7 @@ class TestCopyClass(test.bootstrap.IFC4):
|
|||||||
def test_copying_a_container_only_and_not_its_decomposition(self):
|
def test_copying_a_container_only_and_not_its_decomposition(self):
|
||||||
element = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcBuilding")
|
element = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcBuilding")
|
||||||
subelement = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcBuildingStorey")
|
subelement = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcBuildingStorey")
|
||||||
ifcopenshell.api.run("aggregate.assign_object", self.file, product=subelement, relating_object=element)
|
ifcopenshell.api.run("aggregate.assign_object", self.file, products=[subelement], relating_object=element)
|
||||||
new = ifcopenshell.api.run("root.copy_class", self.file, product=element)
|
new = ifcopenshell.api.run("root.copy_class", self.file, product=element)
|
||||||
assert element.IsDecomposedBy
|
assert element.IsDecomposedBy
|
||||||
assert not new.IsDecomposedBy
|
assert not new.IsDecomposedBy
|
||||||
@@ -97,7 +97,7 @@ class TestCopyClass(test.bootstrap.IFC4):
|
|||||||
def test_copying_an_aggregate_only_and_not_its_decomposition(self):
|
def test_copying_an_aggregate_only_and_not_its_decomposition(self):
|
||||||
element = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcElementAssembly")
|
element = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcElementAssembly")
|
||||||
subelement = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcBeam")
|
subelement = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcBeam")
|
||||||
ifcopenshell.api.run("aggregate.assign_object", self.file, product=subelement, relating_object=element)
|
ifcopenshell.api.run("aggregate.assign_object", self.file, products=[subelement], relating_object=element)
|
||||||
new = ifcopenshell.api.run("root.copy_class", self.file, product=element)
|
new = ifcopenshell.api.run("root.copy_class", self.file, product=element)
|
||||||
assert element.IsDecomposedBy
|
assert element.IsDecomposedBy
|
||||||
assert not new.IsDecomposedBy
|
assert not new.IsDecomposedBy
|
||||||
@@ -105,7 +105,7 @@ class TestCopyClass(test.bootstrap.IFC4):
|
|||||||
def test_copying_an_aggregate_decomposition_and_maintaining_the_aggregate_relationship(self):
|
def test_copying_an_aggregate_decomposition_and_maintaining_the_aggregate_relationship(self):
|
||||||
element = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcElementAssembly")
|
element = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcElementAssembly")
|
||||||
subelement = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcBeam")
|
subelement = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcBeam")
|
||||||
ifcopenshell.api.run("aggregate.assign_object", self.file, product=subelement, relating_object=element)
|
ifcopenshell.api.run("aggregate.assign_object", self.file, products=[subelement], relating_object=element)
|
||||||
new = ifcopenshell.api.run("root.copy_class", self.file, product=subelement)
|
new = ifcopenshell.api.run("root.copy_class", self.file, product=subelement)
|
||||||
assert new.Decomposes[0].RelatingObject == element
|
assert new.Decomposes[0].RelatingObject == element
|
||||||
|
|
||||||
|
|||||||
@@ -212,7 +212,7 @@ class TestRemoveProduct(test.bootstrap.IFC4):
|
|||||||
def test_removing_all_aggregate_relationships_of_a_whole(self):
|
def test_removing_all_aggregate_relationships_of_a_whole(self):
|
||||||
element = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcElementAssembly")
|
element = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcElementAssembly")
|
||||||
subelement = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcBeam")
|
subelement = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcBeam")
|
||||||
ifcopenshell.api.run("aggregate.assign_object", self.file, product=subelement, relating_object=element)
|
ifcopenshell.api.run("aggregate.assign_object", self.file, products=[subelement], relating_object=element)
|
||||||
total_entities = len(list(self.file))
|
total_entities = len(list(self.file))
|
||||||
ifcopenshell.api.run("root.remove_product", self.file, product=element)
|
ifcopenshell.api.run("root.remove_product", self.file, product=element)
|
||||||
assert len(list(self.file)) == total_entities - 2
|
assert len(list(self.file)) == total_entities - 2
|
||||||
@@ -223,7 +223,7 @@ class TestRemoveProduct(test.bootstrap.IFC4):
|
|||||||
def test_removing_all_aggregate_relationships_of_a_part(self):
|
def test_removing_all_aggregate_relationships_of_a_part(self):
|
||||||
element = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcElementAssembly")
|
element = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcElementAssembly")
|
||||||
subelement = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcBeam")
|
subelement = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcBeam")
|
||||||
ifcopenshell.api.run("aggregate.assign_object", self.file, product=subelement, relating_object=element)
|
ifcopenshell.api.run("aggregate.assign_object", self.file, products=[subelement], relating_object=element)
|
||||||
total_entities = len(list(self.file))
|
total_entities = len(list(self.file))
|
||||||
ifcopenshell.api.run("root.remove_product", self.file, product=subelement)
|
ifcopenshell.api.run("root.remove_product", self.file, product=subelement)
|
||||||
assert len(list(self.file)) == total_entities - 2
|
assert len(list(self.file)) == total_entities - 2
|
||||||
|
|||||||
@@ -118,6 +118,6 @@ class TestAssignContainer(test.bootstrap.IFC4):
|
|||||||
element = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcBuilding")
|
element = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcBuilding")
|
||||||
aggregate = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcElementAssembly")
|
aggregate = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcElementAssembly")
|
||||||
subelement = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWall")
|
subelement = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWall")
|
||||||
ifcopenshell.api.run("aggregate.assign_object", self.file, product=subelement, relating_object=aggregate)
|
ifcopenshell.api.run("aggregate.assign_object", self.file, products=[subelement], relating_object=aggregate)
|
||||||
ifcopenshell.api.run("spatial.assign_container", self.file, products=[subelement], relating_structure=element)
|
ifcopenshell.api.run("spatial.assign_container", self.file, products=[subelement], relating_structure=element)
|
||||||
assert not ifcopenshell.util.element.get_aggregate(subelement)
|
assert not ifcopenshell.util.element.get_aggregate(subelement)
|
||||||
|
|||||||
@@ -83,3 +83,11 @@ class TestTemporarySupportForDeprecatedAPIArguments(test.bootstrap.IFC4):
|
|||||||
ifcopenshell.api.run("layer.unassign_layer", self.file, item=items[2], layer=layer)
|
ifcopenshell.api.run("layer.unassign_layer", self.file, item=items[2], layer=layer)
|
||||||
assert len(layer.AssignedItems) == 2
|
assert len(layer.AssignedItems) == 2
|
||||||
assert set(layer.AssignedItems) == set(items[:2])
|
assert set(layer.AssignedItems) == set(items[:2])
|
||||||
|
|
||||||
|
@deprecation_check
|
||||||
|
def test_assigning_an_aggregate(self):
|
||||||
|
element = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcSite")
|
||||||
|
subelement = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcBuilding")
|
||||||
|
rel = ifcopenshell.api.run("aggregate.assign_object", self.file, product=subelement, relating_object=element)
|
||||||
|
assert ifcopenshell.util.element.get_aggregate(subelement) == element
|
||||||
|
assert rel.is_a("IfcRelAggregates")
|
||||||
|
|||||||
@@ -706,7 +706,7 @@ class TestGetContainerIFC4(test.bootstrap.IFC4):
|
|||||||
element = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcElementAssembly")
|
element = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcElementAssembly")
|
||||||
building = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcBuilding")
|
building = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcBuilding")
|
||||||
ifcopenshell.api.run("spatial.assign_container", self.file, products=[element], relating_structure=building)
|
ifcopenshell.api.run("spatial.assign_container", self.file, products=[element], relating_structure=building)
|
||||||
ifcopenshell.api.run("aggregate.assign_object", self.file, product=subelement, relating_object=element)
|
ifcopenshell.api.run("aggregate.assign_object", self.file, products=[subelement], relating_object=element)
|
||||||
assert subject.get_container(subelement) == building
|
assert subject.get_container(subelement) == building
|
||||||
|
|
||||||
def test_getting_nothing_if_we_enforce_only_getting_direct_spatial_containers(self):
|
def test_getting_nothing_if_we_enforce_only_getting_direct_spatial_containers(self):
|
||||||
@@ -714,7 +714,7 @@ class TestGetContainerIFC4(test.bootstrap.IFC4):
|
|||||||
element = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcElementAssembly")
|
element = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcElementAssembly")
|
||||||
building = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcBuilding")
|
building = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcBuilding")
|
||||||
ifcopenshell.api.run("spatial.assign_container", self.file, products=[element], relating_structure=building)
|
ifcopenshell.api.run("spatial.assign_container", self.file, products=[element], relating_structure=building)
|
||||||
ifcopenshell.api.run("aggregate.assign_object", self.file, product=subelement, relating_object=element)
|
ifcopenshell.api.run("aggregate.assign_object", self.file, products=[subelement], relating_object=element)
|
||||||
assert subject.get_container(subelement, should_get_direct=True) is None
|
assert subject.get_container(subelement, should_get_direct=True) is None
|
||||||
|
|
||||||
|
|
||||||
@@ -736,7 +736,7 @@ class TestGetDecompositionIFC4(test.bootstrap.IFC4):
|
|||||||
subelement = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcBeam")
|
subelement = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcBeam")
|
||||||
building = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcBuilding")
|
building = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcBuilding")
|
||||||
ifcopenshell.api.run("spatial.assign_container", self.file, products=[element], relating_structure=building)
|
ifcopenshell.api.run("spatial.assign_container", self.file, products=[element], relating_structure=building)
|
||||||
ifcopenshell.api.run("aggregate.assign_object", self.file, product=subelement, relating_object=element)
|
ifcopenshell.api.run("aggregate.assign_object", self.file, products=[subelement], relating_object=element)
|
||||||
results = subject.get_decomposition(building)
|
results = subject.get_decomposition(building)
|
||||||
assert element in results
|
assert element in results
|
||||||
assert subelement in results
|
assert subelement in results
|
||||||
@@ -756,7 +756,7 @@ class TestGetAggregateIFC4(test.bootstrap.IFC4):
|
|||||||
def test_getting_the_containing_aggregate_of_a_subelement(self):
|
def test_getting_the_containing_aggregate_of_a_subelement(self):
|
||||||
element = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWall")
|
element = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWall")
|
||||||
subelement = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcCovering")
|
subelement = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcCovering")
|
||||||
ifcopenshell.api.run("aggregate.assign_object", self.file, product=subelement, relating_object=element)
|
ifcopenshell.api.run("aggregate.assign_object", self.file, products=[subelement], relating_object=element)
|
||||||
assert subject.get_aggregate(subelement) == element
|
assert subject.get_aggregate(subelement) == element
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -236,9 +236,9 @@ class TestFilterElements(test.bootstrap.IFC4):
|
|||||||
project = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcProject", name="Project")
|
project = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcProject", name="Project")
|
||||||
ifcopenshell.api.run("spatial.assign_container", self.file, products=[element], relating_structure=space)
|
ifcopenshell.api.run("spatial.assign_container", self.file, products=[element], relating_structure=space)
|
||||||
ifcopenshell.api.run("spatial.assign_container", self.file, products=[element2], relating_structure=storey)
|
ifcopenshell.api.run("spatial.assign_container", self.file, products=[element2], relating_structure=storey)
|
||||||
ifcopenshell.api.run("aggregate.assign_object", self.file, product=space, relating_object=storey)
|
ifcopenshell.api.run("aggregate.assign_object", self.file, products=[space], relating_object=storey)
|
||||||
ifcopenshell.api.run("aggregate.assign_object", self.file, product=storey, relating_object=building)
|
ifcopenshell.api.run("aggregate.assign_object", self.file, products=[storey], relating_object=building)
|
||||||
ifcopenshell.api.run("aggregate.assign_object", self.file, product=building, relating_object=project)
|
ifcopenshell.api.run("aggregate.assign_object", self.file, products=[building], relating_object=project)
|
||||||
assert subject.filter_elements(self.file, "IfcWall, location=NULL") == set()
|
assert subject.filter_elements(self.file, "IfcWall, location=NULL") == set()
|
||||||
assert subject.filter_elements(self.file, "IfcWall, location=Space") == {element}
|
assert subject.filter_elements(self.file, "IfcWall, location=Space") == {element}
|
||||||
assert subject.filter_elements(self.file, "IfcWall, location=G") == {element, element2}
|
assert subject.filter_elements(self.file, "IfcWall, location=G") == {element, element2}
|
||||||
@@ -469,7 +469,7 @@ class TestSelector(test.bootstrap.IFC4):
|
|||||||
subelement = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcMember")
|
subelement = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcMember")
|
||||||
building = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcBuilding")
|
building = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcBuilding")
|
||||||
ifcopenshell.api.run("spatial.assign_container", self.file, products=[element], relating_structure=building)
|
ifcopenshell.api.run("spatial.assign_container", self.file, products=[element], relating_structure=building)
|
||||||
ifcopenshell.api.run("aggregate.assign_object", self.file, product=subelement, relating_object=element)
|
ifcopenshell.api.run("aggregate.assign_object", self.file, products=[subelement], relating_object=element)
|
||||||
assert set(subject.Selector.parse(self.file, "@ .IfcBuilding")) == {element, subelement}
|
assert set(subject.Selector.parse(self.file, "@ .IfcBuilding")) == {element, subelement}
|
||||||
|
|
||||||
def test_selecting_elements_from_a_prefiltered_list(self):
|
def test_selecting_elements_from_a_prefiltered_list(self):
|
||||||
|
|||||||
@@ -42,8 +42,8 @@ class TestExtractElements:
|
|||||||
building = ifcopenshell.api.run("root.create_entity", ifc_file, ifc_class="IfcBuilding")
|
building = ifcopenshell.api.run("root.create_entity", ifc_file, ifc_class="IfcBuilding")
|
||||||
storey = ifcopenshell.api.run("root.create_entity", ifc_file, ifc_class="IfcBuildingStorey")
|
storey = ifcopenshell.api.run("root.create_entity", ifc_file, ifc_class="IfcBuildingStorey")
|
||||||
wall = ifcopenshell.api.run("root.create_entity", ifc_file, ifc_class="IfcWall")
|
wall = ifcopenshell.api.run("root.create_entity", ifc_file, ifc_class="IfcWall")
|
||||||
ifcopenshell.api.run("aggregate.assign_object", ifc_file, product=building, relating_object=site)
|
ifcopenshell.api.run("aggregate.assign_object", ifc_file, products=[building], relating_object=site)
|
||||||
ifcopenshell.api.run("aggregate.assign_object", ifc_file, product=storey, relating_object=building)
|
ifcopenshell.api.run("aggregate.assign_object", ifc_file, products=[storey], relating_object=building)
|
||||||
ifcopenshell.api.run("spatial.assign_container", ifc_file, products=[wall], relating_structure=storey)
|
ifcopenshell.api.run("spatial.assign_container", ifc_file, products=[wall], relating_structure=storey)
|
||||||
|
|
||||||
output = ifcpatch.execute({"file": ifc_file, "recipe": "ExtractElements", "arguments": ["IfcWall"]})
|
output = ifcpatch.execute({"file": ifc_file, "recipe": "ExtractElements", "arguments": ["IfcWall"]})
|
||||||
@@ -61,7 +61,7 @@ class TestExtractElements:
|
|||||||
container = ifcopenshell.api.run("root.create_entity", ifc_file, ifc_class="IfcBuildingStorey")
|
container = ifcopenshell.api.run("root.create_entity", ifc_file, ifc_class="IfcBuildingStorey")
|
||||||
subelement = ifcopenshell.api.run("root.create_entity", ifc_file, ifc_class="IfcWall")
|
subelement = ifcopenshell.api.run("root.create_entity", ifc_file, ifc_class="IfcWall")
|
||||||
ifcopenshell.api.run("spatial.assign_container", ifc_file, products=[element], relating_structure=container)
|
ifcopenshell.api.run("spatial.assign_container", ifc_file, products=[element], relating_structure=container)
|
||||||
ifcopenshell.api.run("aggregate.assign_object", ifc_file, product=subelement, relating_object=element)
|
ifcopenshell.api.run("aggregate.assign_object", ifc_file, products=[subelement], relating_object=element)
|
||||||
|
|
||||||
output = ifcpatch.execute({"file": ifc_file, "recipe": "ExtractElements", "arguments": ["IfcWall"]})
|
output = ifcpatch.execute({"file": ifc_file, "recipe": "ExtractElements", "arguments": ["IfcWall"]})
|
||||||
|
|
||||||
|
|||||||
@@ -179,7 +179,7 @@ class IFC_Sv_write_file(bpy.types.Operator):
|
|||||||
if not (spatial.is_a("IfcSite") or spatial.is_a("IfcBuilding")) and (spatial not in elements_in_buildings):
|
if not (spatial.is_a("IfcSite") or spatial.is_a("IfcBuilding")) and (spatial not in elements_in_buildings):
|
||||||
elements = ifcopenshell.util.element.get_decomposition(spatial)
|
elements = ifcopenshell.util.element.get_decomposition(spatial)
|
||||||
ifcopenshell.api.run(
|
ifcopenshell.api.run(
|
||||||
"aggregate.assign_object", file, product=spatial, relating_object=file.by_type("IfcBuilding")[0]
|
"aggregate.assign_object", file, products=[spatial], relating_object=file.by_type("IfcBuilding")[0]
|
||||||
)
|
)
|
||||||
|
|
||||||
for building in file.by_type("IfcBuilding"):
|
for building in file.by_type("IfcBuilding"):
|
||||||
@@ -202,7 +202,7 @@ class IFC_Sv_write_file(bpy.types.Operator):
|
|||||||
if len(file.by_type("IfcSite")) == 0:
|
if len(file.by_type("IfcSite")) == 0:
|
||||||
ifcopenshell.api.run("root.create_entity", file, ifc_class="IfcSite", name="My Site")
|
ifcopenshell.api.run("root.create_entity", file, ifc_class="IfcSite", name="My Site")
|
||||||
ifcopenshell.api.run(
|
ifcopenshell.api.run(
|
||||||
"aggregate.assign_object", file, product=building, relating_object=file.by_type("IfcSite")[0]
|
"aggregate.assign_object", file, products=[building], relating_object=file.by_type("IfcSite")[0]
|
||||||
)
|
)
|
||||||
try:
|
try:
|
||||||
if file.by_type("IfcSite")[0].Decomposes[0].RelatingObject.is_a("IfcProject"):
|
if file.by_type("IfcSite")[0].Decomposes[0].RelatingObject.is_a("IfcProject"):
|
||||||
@@ -212,7 +212,7 @@ class IFC_Sv_write_file(bpy.types.Operator):
|
|||||||
ifcopenshell.api.run(
|
ifcopenshell.api.run(
|
||||||
"aggregate.assign_object",
|
"aggregate.assign_object",
|
||||||
file,
|
file,
|
||||||
product=file.by_type("IfcSite")[0],
|
products=[file.by_type("IfcSite")[0]],
|
||||||
relating_object=file.by_type("IfcProject")[0],
|
relating_object=file.by_type("IfcProject")[0],
|
||||||
)
|
)
|
||||||
self.file = file
|
self.file = file
|
||||||
|
|||||||
@@ -135,7 +135,7 @@ class SvIfcAddSpatialElement(bpy.types.Node, SverchCustomTreeNode, ifcsverchok.h
|
|||||||
ifcopenshell.api.run(
|
ifcopenshell.api.run(
|
||||||
"aggregate.assign_object",
|
"aggregate.assign_object",
|
||||||
self.file,
|
self.file,
|
||||||
product=items,
|
products=[items],
|
||||||
relating_object=result,
|
relating_object=result,
|
||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
@@ -188,7 +188,7 @@ class SvIfcAddSpatialElement(bpy.types.Node, SverchCustomTreeNode, ifcsverchok.h
|
|||||||
ifcopenshell.api.run(
|
ifcopenshell.api.run(
|
||||||
"aggregate.assign_object",
|
"aggregate.assign_object",
|
||||||
self.file,
|
self.file,
|
||||||
product=added_element,
|
products=[added_element],
|
||||||
relating_object=result,
|
relating_object=result,
|
||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
|
|||||||
@@ -93,7 +93,7 @@ class SvIfcWriteFile(bpy.types.Node, SverchCustomTreeNode, ifcsverchok.helper.Sv
|
|||||||
ifcopenshell.api.run(
|
ifcopenshell.api.run(
|
||||||
"aggregate.assign_object",
|
"aggregate.assign_object",
|
||||||
file,
|
file,
|
||||||
product=spatial,
|
products=[spatial],
|
||||||
relating_object=file.by_type("IfcBuilding")[0],
|
relating_object=file.by_type("IfcBuilding")[0],
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -120,7 +120,7 @@ class SvIfcWriteFile(bpy.types.Node, SverchCustomTreeNode, ifcsverchok.helper.Sv
|
|||||||
ifcopenshell.api.run(
|
ifcopenshell.api.run(
|
||||||
"aggregate.assign_object",
|
"aggregate.assign_object",
|
||||||
file,
|
file,
|
||||||
product=building,
|
products=[building],
|
||||||
relating_object=file.by_type("IfcSite")[0],
|
relating_object=file.by_type("IfcSite")[0],
|
||||||
)
|
)
|
||||||
try:
|
try:
|
||||||
@@ -131,7 +131,7 @@ class SvIfcWriteFile(bpy.types.Node, SverchCustomTreeNode, ifcsverchok.helper.Sv
|
|||||||
ifcopenshell.api.run(
|
ifcopenshell.api.run(
|
||||||
"aggregate.assign_object",
|
"aggregate.assign_object",
|
||||||
file,
|
file,
|
||||||
product=file.by_type("IfcSite")[0],
|
products=[file.by_type("IfcSite")[0]],
|
||||||
relating_object=file.by_type("IfcProject")[0],
|
relating_object=file.by_type("IfcProject")[0],
|
||||||
)
|
)
|
||||||
self.file = file
|
self.file = file
|
||||||
|
|||||||
@@ -320,9 +320,9 @@ site = ifcopenshell.api.run("root.create_entity", model, ifc_class="IfcSite", na
|
|||||||
building = ifcopenshell.api.run("root.create_entity", model, ifc_class="IfcBuilding", name="Building A")
|
building = ifcopenshell.api.run("root.create_entity", model, ifc_class="IfcBuilding", name="Building A")
|
||||||
storey = ifcopenshell.api.run("root.create_entity", model, ifc_class="IfcBuildingStorey", name="Ground Floor")
|
storey = ifcopenshell.api.run("root.create_entity", model, ifc_class="IfcBuildingStorey", name="Ground Floor")
|
||||||
|
|
||||||
ifcopenshell.api.run("aggregate.assign_object", model, relating_object=project, product=site)
|
ifcopenshell.api.run("aggregate.assign_object", model, relating_object=project, products=[site])
|
||||||
ifcopenshell.api.run("aggregate.assign_object", model, relating_object=site, product=building)
|
ifcopenshell.api.run("aggregate.assign_object", model, relating_object=site, products=[building])
|
||||||
ifcopenshell.api.run("aggregate.assign_object", model, relating_object=building, product=storey)
|
ifcopenshell.api.run("aggregate.assign_object", model, relating_object=building, products=[storey])
|
||||||
|
|
||||||
wall_types = []
|
wall_types = []
|
||||||
for i in range(0, 4):
|
for i in range(0, 4):
|
||||||
|
|||||||
@@ -1428,7 +1428,7 @@ class TestPartOf:
|
|||||||
subelement = ifcopenshell.api.run("root.create_entity", ifc, ifc_class="IfcWall")
|
subelement = ifcopenshell.api.run("root.create_entity", ifc, ifc_class="IfcWall")
|
||||||
facet = PartOf(name="IFCELEMENTASSEMBLY", relation="IFCRELAGGREGATES")
|
facet = PartOf(name="IFCELEMENTASSEMBLY", relation="IFCRELAGGREGATES")
|
||||||
run("A non aggregated element fails an aggregate relationship", facet=facet, inst=subelement, expected=False)
|
run("A non aggregated element fails an aggregate relationship", facet=facet, inst=subelement, expected=False)
|
||||||
ifcopenshell.api.run("aggregate.assign_object", ifc, product=subelement, relating_object=element)
|
ifcopenshell.api.run("aggregate.assign_object", ifc, products=[subelement], relating_object=element)
|
||||||
run("The aggregated whole fails an aggregate relationship", facet=facet, inst=element, expected=False)
|
run("The aggregated whole fails an aggregate relationship", facet=facet, inst=element, expected=False)
|
||||||
run("The aggregated part passes an aggregate relationship", facet=facet, inst=subelement, expected=True)
|
run("The aggregated part passes an aggregate relationship", facet=facet, inst=subelement, expected=True)
|
||||||
|
|
||||||
@@ -1439,7 +1439,7 @@ class TestPartOf:
|
|||||||
ifc = ifcopenshell.file()
|
ifc = ifcopenshell.file()
|
||||||
element = ifcopenshell.api.run("root.create_entity", ifc, ifc_class="IfcSlab")
|
element = ifcopenshell.api.run("root.create_entity", ifc, ifc_class="IfcSlab")
|
||||||
subelement = ifcopenshell.api.run("root.create_entity", ifc, ifc_class="IfcBeam")
|
subelement = ifcopenshell.api.run("root.create_entity", ifc, ifc_class="IfcBeam")
|
||||||
ifcopenshell.api.run("aggregate.assign_object", ifc, product=subelement, relating_object=element)
|
ifcopenshell.api.run("aggregate.assign_object", ifc, products=[subelement], relating_object=element)
|
||||||
facet = PartOf(name="IFCSLAB", relation="IFCRELAGGREGATES")
|
facet = PartOf(name="IFCSLAB", relation="IFCRELAGGREGATES")
|
||||||
run("An aggregate may specify the entity of the whole 1/2", facet=facet, inst=subelement, expected=True)
|
run("An aggregate may specify the entity of the whole 1/2", facet=facet, inst=subelement, expected=True)
|
||||||
facet = PartOf(name="IFCWALL", relation="IFCRELAGGREGATES")
|
facet = PartOf(name="IFCWALL", relation="IFCRELAGGREGATES")
|
||||||
@@ -1462,8 +1462,8 @@ class TestPartOf:
|
|||||||
element = ifcopenshell.api.run("root.create_entity", ifc, ifc_class="IfcElementAssembly")
|
element = ifcopenshell.api.run("root.create_entity", ifc, ifc_class="IfcElementAssembly")
|
||||||
subelement = ifcopenshell.api.run("root.create_entity", ifc, ifc_class="IfcSlab")
|
subelement = ifcopenshell.api.run("root.create_entity", ifc, ifc_class="IfcSlab")
|
||||||
subsubelement = ifcopenshell.api.run("root.create_entity", ifc, ifc_class="IfcBeam")
|
subsubelement = ifcopenshell.api.run("root.create_entity", ifc, ifc_class="IfcBeam")
|
||||||
ifcopenshell.api.run("aggregate.assign_object", ifc, product=subelement, relating_object=element)
|
ifcopenshell.api.run("aggregate.assign_object", ifc, products=[subelement], relating_object=element)
|
||||||
ifcopenshell.api.run("aggregate.assign_object", ifc, product=subsubelement, relating_object=subelement)
|
ifcopenshell.api.run("aggregate.assign_object", ifc, products=[subsubelement], relating_object=subelement)
|
||||||
facet = PartOf(name="IFCELEMENTASSEMBLY", relation="IFCRELAGGREGATES")
|
facet = PartOf(name="IFCELEMENTASSEMBLY", relation="IFCRELAGGREGATES")
|
||||||
run("An aggregate entity may pass any ancestral whole passes", facet=facet, inst=subsubelement, expected=True)
|
run("An aggregate entity may pass any ancestral whole passes", facet=facet, inst=subsubelement, expected=True)
|
||||||
|
|
||||||
@@ -1517,7 +1517,7 @@ class TestPartOf:
|
|||||||
ifc = ifcopenshell.file()
|
ifc = ifcopenshell.file()
|
||||||
element = ifcopenshell.api.run("root.create_entity", ifc, ifc_class="IfcSlab")
|
element = ifcopenshell.api.run("root.create_entity", ifc, ifc_class="IfcSlab")
|
||||||
subelement = ifcopenshell.api.run("root.create_entity", ifc, ifc_class="IfcBeam")
|
subelement = ifcopenshell.api.run("root.create_entity", ifc, ifc_class="IfcBeam")
|
||||||
ifcopenshell.api.run("aggregate.assign_object", ifc, product=subelement, relating_object=element)
|
ifcopenshell.api.run("aggregate.assign_object", ifc, products=[subelement], relating_object=element)
|
||||||
container = ifcopenshell.api.run("root.create_entity", ifc, ifc_class="IfcSpace")
|
container = ifcopenshell.api.run("root.create_entity", ifc, ifc_class="IfcSpace")
|
||||||
ifcopenshell.api.run("spatial.assign_container", ifc, products=[element], relating_structure=container)
|
ifcopenshell.api.run("spatial.assign_container", ifc, products=[element], relating_structure=container)
|
||||||
facet = PartOf(relation="IFCRELCONTAINEDINSPATIALSTRUCTURE", name="IFCSPACE")
|
facet = PartOf(relation="IFCRELCONTAINEDINSPATIALSTRUCTURE", name="IFCSPACE")
|
||||||
|
|||||||
Reference in New Issue
Block a user