From 5e394e157612a9e5c72a7f4106ac79745ad1e691 Mon Sep 17 00:00:00 2001 From: Andrej730 Date: Mon, 13 May 2024 17:10:21 +0500 Subject: [PATCH] library.edit_library - support datetime for VersionDate attribute --- .../ifcopenshell/api/library/edit_library.py | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/src/ifcopenshell-python/ifcopenshell/api/library/edit_library.py b/src/ifcopenshell-python/ifcopenshell/api/library/edit_library.py index 81b96c0692..fa4e6b5229 100644 --- a/src/ifcopenshell-python/ifcopenshell/api/library/edit_library.py +++ b/src/ifcopenshell-python/ifcopenshell/api/library/edit_library.py @@ -16,6 +16,8 @@ # You should have received a copy of the GNU Lesser General Public License # along with IfcOpenShell. If not, see . import ifcopenshell +import ifcopenshell.util.date +import datetime from typing import Any @@ -41,7 +43,16 @@ def edit_library(file: ifcopenshell.file, library: ifcopenshell.entity_instance, attributes={"Description": "A Brickschema TTL including only mechanical distribution systems."}) """ - settings = {"library": library, "attributes": attributes} + if "VersionDate" in attributes: + dt = attributes["VersionDate"] + if isinstance(dt, datetime.datetime): + if file.schema != "IFC2X3": + dt = ifcopenshell.util.date.datetime2ifc(dt, "IfcDateTime") + else: + calendar_date = ifcopenshell.util.date.datetime2ifc(dt, "IfcCalendarDate") + dt = file.create_entity("IfcCalendarDate", **calendar_date) + attributes = attributes.copy() + attributes["VersionDate"] = dt - for name, value in settings["attributes"].items(): - setattr(settings["library"], name, value) + for name, value in attributes.items(): + setattr(library, name, value)