remove_work_plan - unassign work schedules #4819

This commit is contained in:
Andrej730
2024-06-07 17:13:56 +05:00
parent f8a5ce34a8
commit 5c41baeaf1
3 changed files with 53 additions and 1 deletions
@@ -20,6 +20,7 @@ import ifcopenshell
import ifcopenshell.api
# TODO: rename to assign_work_plan for consistency
def assign_workplan(
file: ifcopenshell.file, work_schedule: ifcopenshell.entity_instance, work_plan: ifcopenshell.entity_instance
) -> ifcopenshell.entity_instance:
@@ -18,6 +18,7 @@
import ifcopenshell
import ifcopenshell.api
import ifcopenshell.api.aggregate
import ifcopenshell.util.element
@@ -44,13 +45,17 @@ def remove_work_plan(file: ifcopenshell.file, work_plan: ifcopenshell.entity_ins
"""
settings = {"work_plan": work_plan}
# TODO: do a deep purge
ifcopenshell.api.run(
"project.unassign_declaration",
file,
definitions=[settings["work_plan"]],
relating_context=file.by_type("IfcContext")[0],
)
related_objects = [obj for rel in work_plan.IsDecomposedBy for obj in rel.RelatedObjects]
if related_objects:
ifcopenshell.api.aggregate.unassign_object(file, related_objects)
history = settings["work_plan"].OwnerHistory
file.remove(settings["work_plan"])
if history: