Import from XML#

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

Importing model data from XML and listing created RFEM objects:

  • Create a clean RFEM model

  • Import model data from an XML file

  • Get the list of object IDs after import

  • Print the type and ID for each imported object

Keywords:
XML import object IDs model import object list
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}")