OSArch Community

IfcTask & IfcTaskTime - ifcopenshell

  1. M

    i'm trying through code to be able to iterate through all IfcProducts, and to list and IfcTask and IfcTaskTime properties.

    for example i need to extract IfcTaskTime dates.

    id: 464

    type: IfcTaskTime

    Name: ExampleTestNAme

    DataOrigin: USERDEFINED

    UserDefinedDataOrigin: None

    DurationType: None

    ScheduleDuration: None

    ScheduleStart: 2025-12-01T08:00:00

    ScheduleFinish: 2025-12-03T16:00:00

    EarlyStart: None

    EarlyFinish: None

    LateStart: None

    LateFinish: None

    FreeFloat: None

    TotalFloat: None

    IsCritical: None

    StatusTime: None

    ActualDuration: None

    ActualStart: None

    ActualFinish: None

    RemainingTime: None

    Completion: None

    i can find this information, but i cant seem to link it back to the IfcTask, which is linked with IfcProduct in this example.

    IfcPile is in a relationship with IfcTask using IfcRealAssignedToProduct,

    IfcTaskTime is in a relationship with IfcTask using IfcTealAssignedToProcess.

    i can see this in the the .Ifc read in notepad. i just cant seem to figure out how to read IfcTaskTime, and see what IfcTask is associated an in turn also know which IfcProduct is assigned.

    my latest attempt look like this, greatful for any support or ideas, where i might be going wrong

    import ifcopenshell

    Load the IFC file

    ifc_file_path = r"location to ifc file"

    ifc_file = ifcopenshell.open(ifc_file_path)

    for rel in ifc_file.by_type("IfcRelAssignsToProcess"):

    print(f"RelatingProcess: {rel.RelatingProcess}")
    
    print(f"RelatedObjects: {rel.RelatedObjects}")

    Debug: Print all IfcRelAssignsToProcess objects and their details

    print("\n--- Debug: IfcRelAssignsToProcess Relationships ---")

    for rel in ifc_file.by_type("IfcRelAssignsToProcess"):

    print(f"RelatingProcess: {rel.RelatingProcess}")
    
    print(f"RelatedObjects: {rel.RelatedObjects}")
    
    for related_obj in rel.RelatedObjects:
    
        print(f"  RelatedObject: {related_obj}")
    
        if related_obj.is_a("IfcTaskTime"):
    
            print(f"    Is a TaskTime: {related_obj}")
    
            print(f"    TaskTime ScheduleStart: {getattr(related_obj, 'ScheduleStart', 'No ScheduleStart')}")
    
            print(f"    TaskTime ScheduleFinish: {getattr(related_obj, 'ScheduleFinish', 'No ScheduleFinish')}")
    
            print(f"    TaskTime ScheduleDuration: {getattr(related_obj, 'ScheduleDuration', 'No ScheduleDuration')}")

    Extract tasks related to IfcPile

    tasks_related_to_piles = []

    for rel in ifc_file.by_type("IfcRelAssignsToProduct"):

    if rel.RelatingProduct.is_a("IfcPile"):  # Check if relating object is IfcPile
    
        tasks_related_to_piles.extend(rel.RelatedObjects)

    Debug: List the tasks related to IfcPile

    print("\n--- Debug: Tasks Related to IfcPile ---")

    for task in tasks_related_to_piles:

    print(f"Related Task: {task}")

    Extract TaskTime relationships

    results = []

    for task in tasks_related_to_piles:

    task_name = getattr(task, "Name", "Unnamed Task")
    
    task_time_details = "No TaskTime Assigned"
    
    print(f"Checking Task: {task_name} for TaskTime...")
    
    for rel in ifc_file.by_type("IfcRelAssignsToProcess"):
    
        print(f"  Checking RelatingProcess: {rel.RelatingProcess}")
    
        if rel.RelatingProcess == task:  # Match task with process
    
            print(f"    Found related task: {task.Name}")
    
            for related_obj in rel.RelatedObjects:
    
                print(f"    Checking related object: {related_obj}")
    
                if related_obj.is_a("IfcTaskTime"):  # Check for IfcTaskTime
    
                    task_time_details = f"Start: {getattr(related_obj, 'ScheduleStart', 'No Start Time')}, Finish: {getattr(related_obj, 'ScheduleFinish', 'No Finish Time')}, Duration: {getattr(related_obj, 'ScheduleDuration', 'No Duration')}"
    
                    print(f"    Found TaskTime: {task_time_details}")
    
    results.append((task_name, task_time_details))

    Output results

    print("\n--- Results: Task and TaskTime Details ---")

    for task_name, task_time_details in results:

    print(f"Task: {task_name}, TaskTime: {task_time_details}")
  2. M

Login or Register to reply.