sequence.remove_work_time to remove IfcRecurrencePattern

Previously it was leaving them orphaned.
This commit is contained in:
Andrej730
2024-06-10 12:45:04 +05:00
parent 1343741cfd
commit 6cab7d964e
3 changed files with 52 additions and 3 deletions
@@ -16,10 +16,13 @@
# You should have received a copy of the GNU Lesser General Public License
# along with IfcOpenShell. If not, see <http://www.gnu.org/licenses/>.
import ifcopenshell
import ifcopenshell.util.sequence
def assign_recurrence_pattern(
file: ifcopenshell.file, parent: ifcopenshell.entity_instance, recurrence_type: str = "WEEKLY"
file: ifcopenshell.file,
parent: ifcopenshell.entity_instance,
recurrence_type: ifcopenshell.util.sequence.RECURRENCE_TYPE = "WEEKLY",
) -> ifcopenshell.entity_instance:
"""Define a time to recur at a particular interval
@@ -16,6 +16,7 @@
# You should have received a copy of the GNU Lesser General Public License
# along with IfcOpenShell. If not, see <http://www.gnu.org/licenses/>.
import ifcopenshell
import ifcopenshell.api.sequence
def remove_work_time(file: ifcopenshell.file, work_time: ifcopenshell.entity_instance) -> None:
@@ -40,6 +41,10 @@ def remove_work_time(file: ifcopenshell.file, work_time: ifcopenshell.entity_ins
# And remove it immediately
ifcopenshell.api.run("sequence.remove_work_time", model, work_time=work_time)
"""
settings = {"work_time": work_time}
file.remove(settings["work_time"])
# Currently in API recurrence patterns are created during assignment
# and removed during unassignment, so they are never reused.
if recurrence_pattern := work_time.RecurrencePattern:
ifcopenshell.api.sequence.unassign_recurrence_pattern(file, recurrence_pattern)
file.remove(work_time)