diff --git a/src/ifcopenshell-python/ifcopenshell/api/sequence/add_work_plan.py b/src/ifcopenshell-python/ifcopenshell/api/sequence/add_work_plan.py index 7754446882..75ab9944be 100644 --- a/src/ifcopenshell-python/ifcopenshell/api/sequence/add_work_plan.py +++ b/src/ifcopenshell-python/ifcopenshell/api/sequence/add_work_plan.py @@ -71,10 +71,11 @@ def add_work_plan( work_plan.Creators = [user.ThePerson] work_plan.StartTime = ifcopenshell.api.sequence.add_date_time(file, datetime.now()) - context = file.by_type("IfcContext")[0] - ifcopenshell.api.project.assign_declaration( - file, - definitions=[work_plan], - relating_context=context, - ) + if file.schema != "IFC2X3": + context = file.by_type("IfcContext")[0] + ifcopenshell.api.project.assign_declaration( + file, + definitions=[work_plan], + relating_context=context, + ) return work_plan diff --git a/src/ifcopenshell-python/ifcopenshell/util/sequence.py b/src/ifcopenshell-python/ifcopenshell/util/sequence.py index babcfd6fbc..930184ecdb 100644 --- a/src/ifcopenshell-python/ifcopenshell/util/sequence.py +++ b/src/ifcopenshell-python/ifcopenshell/util/sequence.py @@ -18,6 +18,7 @@ import datetime import ifcopenshell.util.date +import ifcopenshell.util.element from math import floor from functools import cache from typing import Union, Literal, Optional @@ -280,7 +281,7 @@ def get_task_work_schedule(task: ifcopenshell.entity_instance) -> Union[ifcopens def get_nested_tasks(task: ifcopenshell.entity_instance) -> list[ifcopenshell.entity_instance]: - return [object for rel in task.IsNestedBy or [] for object in rel.RelatedObjects if object.is_a("IfcTask")] + return [obj for obj in ifcopenshell.util.element.get_components(task) if obj.is_a("IfcTask")] def get_parent_task(task: ifcopenshell.entity_instance) -> Union[ifcopenshell.entity_instance, None]: diff --git a/src/ifcopenshell-python/test/api/sequence/test_copy_work_schedule.py b/src/ifcopenshell-python/test/api/sequence/test_copy_work_schedule.py index 7bb686ceb6..368738eeaf 100644 --- a/src/ifcopenshell-python/test/api/sequence/test_copy_work_schedule.py +++ b/src/ifcopenshell-python/test/api/sequence/test_copy_work_schedule.py @@ -43,5 +43,9 @@ class TestCopyWorkSchedule(test.bootstrap.IFC4): assert len(new_tasks.intersection(old_cost_items)) == 0 +class TestCopyWorkScheduleIFC2X3(test.bootstrap.IFC2X3, TestCopyWorkSchedule): + pass + + class TestCopyWorkScheduleIFC4X3(test.bootstrap.IFC4X3, TestCopyWorkSchedule): pass