Import XML#
![]() |
In this example we will demonstrate how to:
|
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}")
using Rfem = Dlubal.Api.Rfem;
using Common = Dlubal.Api.Common;
using Google.Protobuf.WellKnownTypes;
ApplicationRfem? RfemApp = null;
try
{
RfemApp = new ApplicationRfem();
await RfemApp.create_model(name: "import_from_xml");
// Step 1: Import XML model from the file
string ifcFilePath = Path.GetFullPath("xml_structure.xml");
await RfemApp.import_from(
filepath: ifcFilePath,
importAttributes: Any.Pack(new Common.ImportExport.XmlImportAttributes())
);
// Step 2: Get object ID list
var objectIdList = await RfemApp.get_object_id_list();
// Iterate through the object IDs
foreach (var obj in objectIdList.ObjectId)
{
var objectId = obj.No;
var objectType = obj.ObjectType;
Console.WriteLine($"{objectType}: {objectId}");
}
}
catch (Exception ex)
{
Console.WriteLine($"Error: {ex.Message}");
}
finally
{
if (RfemApp != null) await RfemApp.close_connection();
}