Import XML#

../../../_images/import_from_ifc.png

In this example we will demonstrate how to:

  • Import data from an XML file into the RFEM model.

  • Get a list of object IDs in the model after the import.

  • Extract and print the type and ID for each object.

import os
from dlubal.api import rfem, common

# Connect to the RFEM application
with rfem.Application() as rfem_app:

    # Reset RFEM by closing models, creating a new one, and clearing all objects
    rfem_app.close_all_models(save_changes=False)
    rfem_app.create_model(name='xml_structure')
    rfem_app.delete_all_objects()

    # Step 1: Import IFC model from the file
    xml_path = os.path.join(os.path.dirname(__file__), 'src', 'xml_structure.xml')

    rfem_app.import_from(
        filepath=xml_path,
        import_attributes=common.import_export.XmlImportAttributes()
    )

    # Step 2: Get object ID list
    object_id_list = rfem_app.get_object_id_list()

    # Iterate through object IDs and print their types and IDs
    for obj in object_id_list.object_id:

        object_id = obj.no
        object_type = obj.object_type

        print(f"{rfem.ObjectType.Name(object_type)}: {object_id}")