Files
IfcOpenShell/src/ifcopenshell-python/ifcopenshell/api/sequence/remove_work_calendar.py
T

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

72 lines
2.6 KiB
Python
Raw Normal View History

# IfcOpenShell - IFC toolkit and geometry engine
# Copyright (C) 2021 Dion Moult <dion@thinkmoult.com>
#
# This file is part of IfcOpenShell.
#
# IfcOpenShell is free software: you can redistribute it and/or modify
# it under the terms of the GNU Lesser General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# IfcOpenShell is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public License
# along with IfcOpenShell. If not, see <http://www.gnu.org/licenses/>.
2021-04-29 09:55:50 +10:00
import ifcopenshell
import ifcopenshell.api.control
import ifcopenshell.api.project
import ifcopenshell.api.sequence
import ifcopenshell.util.element
2021-04-29 09:55:50 +10:00
2024-05-10 11:21:53 +05:00
def remove_work_calendar(file: ifcopenshell.file, work_calendar: ifcopenshell.entity_instance) -> None:
"""Removes a work calendar
2023-01-03 17:31:48 +11:00
All relationships are also removed, such as if a task is set to use that
calendar.
2023-01-03 17:31:48 +11:00
:param work_calendar: The IfcWorkCalendar to remove
:return: None
2023-01-03 17:31:48 +11:00
Example:
2023-01-10 10:16:28 +11:00
.. code:: python
2023-01-03 17:31:48 +11:00
# Let's create a new calendar.
calendar = ifcopenshell.api.sequence.add_work_calendar(model, name="5 Day Week")
2023-01-03 17:31:48 +11:00
# And remove it immediately
ifcopenshell.api.sequence.remove_work_calendar(model, work_calendar=calendar)
"""
# TODO: do a deep purge
ifcopenshell.api.project.unassign_declaration(
file,
2025-03-14 10:43:47 +05:00
definitions=[work_calendar],
relating_context=file.by_type("IfcContext")[0],
)
2025-03-14 10:43:47 +05:00
if work_calendar.Controls:
for rel in work_calendar.Controls:
for related_object in rel.RelatedObjects:
ifcopenshell.api.control.unassign_control(
file,
2025-03-14 10:43:47 +05:00
relating_control=work_calendar,
related_objects=[related_object],
)
# Currently in API work times are created already attached
# to the work calendar, so they are never reused.
2025-03-14 10:43:47 +05:00
for working_time in work_calendar.WorkingTimes or []:
ifcopenshell.api.sequence.remove_work_time(file, work_time=working_time)
2025-03-14 10:43:47 +05:00
for exception_time in work_calendar.ExceptionTimes or []:
ifcopenshell.api.sequence.remove_work_time(file, work_time=exception_time)
2025-03-14 10:43:47 +05:00
history = work_calendar.OwnerHistory
file.remove(work_calendar)
if history:
ifcopenshell.util.element.remove_deep2(file, history)