Notify user if duration parsing not available in util.date

This commit is contained in:
Dion Moult
2024-05-11 15:14:39 +10:00
parent 8e6c372a4f
commit 6df6553935
3 changed files with 8 additions and 16 deletions
@@ -56,10 +56,6 @@ def add_resource_time(file: ifcopenshell.file, resource: ifcopenshell.entity_ins
ifcopenshell.api.run("resource.edit_resource_time", model,
resource_time=time, attributes={"ScheduleWork": "PT16H"})
"""
settings = {
"resource": resource,
}
resource_time = file.create_entity("IfcResourceTime")
settings["resource"].Usage = resource_time
resource.Usage = resource_time
return resource_time
@@ -56,17 +56,15 @@ def calculate_resource_work(file: ifcopenshell.file, resource: ifcopenshell.enti
:return None:
:rtype: None:
"""
settings = {"resource": resource}
if ifcopenshell.util.constraint.is_attribute_locked(settings["resource"], "Usage.ScheduleWork"):
if ifcopenshell.util.constraint.is_attribute_locked(resource, "Usage.ScheduleWork"):
return
amount_worked = ifcopenshell.util.resource.get_resource_required_work(settings["resource"])
amount_worked = ifcopenshell.util.resource.get_resource_required_work(resource)
if not amount_worked:
return
if not settings["resource"].Usage:
if not resource.Usage:
ifcopenshell.api.run(
"resource.add_resource_time",
file,
resource=settings["resource"],
resource=resource,
)
settings["resource"].Usage.ScheduleWork = amount_worked
resource.Usage.ScheduleWork = amount_worked
@@ -22,8 +22,8 @@ from dateutil import parser
try:
import isodate
except:
pass # Duration parsing not supported
except ModuleNotFoundError as e:
print(f"Note: duration parsing not available due to missing dependencies: util.date - {e}")
def timedelta2duration(timedelta):
@@ -187,8 +187,6 @@ def parse_duration(value):
if "P" in value:
try:
return isodate.parse_duration(value)
except ModuleNotFoundError:
print("Duration parsing not supported: isodate module not found")
except:
print("Error parsing ISO string duration")
return None