Import IFC#
|
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:
rfem_app.create_model(name='import_from_ifc')
# Step 1: Import IFC model from the file
ifc_file_path = os.path.join(os.path.dirname(__file__), 'src', 'ifc_structure.ifc')
rfem_app.import_from(
filepath=ifc_file_path,
import_attributes=common.import_export.IfcImportAttributes()
)
# Step 2: Edit IFC model (e.g., mirror it along the Z-axis)
ifc_model: rfem.ifc_objects.IfcFileModelObject = rfem_app.get_object(
rfem.ifc_objects.IfcFileModelObject(no=1)
)
ifc_model.mirror_axis_z=True
rfem_app.update_object(ifc_model)
# Step 3: Categorize IFC model objects for conversion
ifc_object_list = rfem_app.get_object_list(
objs=[
rfem.ifc_objects.IfcModelObject()
]
)
members, surfaces, solids = [], [], []
for ifc_object in ifc_object_list:
ifc_type = ifc_object.ifc_type
if ifc_type in ["IfcColumn", "IfcBeam"]:
members.append(ifc_object)
elif ifc_type in ["IfcWallStandardCase", "IfcSlab",]:
surfaces.append(ifc_object)
elif ifc_type in ["IfcFooting"]:
solids.append(ifc_object)
# Step 4: Convert IFC model objects to appropriate RFEM model objects
# Convert columns and beams to RFEM straight members
rfem_app.convert_objects(
convert_into=common.ConvertObjectInto.CONVERT_IFC_OBJECT_INTO_STRAIGHT_MEMBER,
objs=members
)
# Convert walls and slabs to RFEM surfaces
rfem_app.convert_objects(
convert_into=common.ConvertObjectInto.CONVERT_IFC_OBJECT_INTO_SURFACE,
objs=surfaces
)
# Convert footings to RFEM solids
rfem_app.convert_objects(
convert_into=common.ConvertObjectInto.CONVERT_IFC_OBJECT_INTO_SOLID,
objs=solids
)
using Rfem = Dlubal.Api.Rfem;
using Common = Dlubal.Api.Common;
using Google.Protobuf.WellKnownTypes;
using Google.Protobuf;
ApplicationRfem? RfemApp = null;
try
{
RfemApp = new ApplicationRfem();
await RfemApp.create_model(name: "import_from_ifc");
// Step 1: Import IFC model from the file
string ifcFilePath = Path.GetFullPath("ifc_structure.ifc");
await RfemApp.import_from(
filepath: ifcFilePath,
importAttributes: Any.Pack(new Common.ImportExport.IfcImportAttributes())
);
// Step 2: Edit IFC model (e.g., mirror it along the Z-axis)
Rfem.IfcObjects.IfcFileModelObject ifcModel = await RfemApp.get_object<Rfem.IfcObjects.IfcFileModelObject>(
obj: new Rfem.IfcObjects.IfcFileModelObject { No = 1 }
);
ifcModel.MirrorAxisZ = true;
await RfemApp.update_object(obj: ifcModel);
// Step 3: Categorize IFC model objects for conversion
var ifcObjectList = await RfemApp.get_object_list(
new List<IMessage> { new Rfem.IfcObjects.IfcModelObject { } }
);
List<IMessage> members = new List<IMessage>();
List<IMessage> surfaces = new List<IMessage>();
List<IMessage> solids = new List<IMessage>();
foreach (var ifcObject in ifcObjectList)
{
if (ifcObject is Rfem.IfcObjects.IfcModelObject ifcModelObject)
{
string ifcType = ifcModelObject.IfcType;
if (ifcType == "IfcColumn" || ifcType == "IfcBeam")
{
members.Add(ifcModelObject);
}
else if (ifcType == "IfcWallStandardCase" || ifcType == "IfcSlab")
{
surfaces.Add(ifcModelObject);
}
else if (ifcType == "IfcFooting")
{
solids.Add(ifcModelObject);
}
}
}
// Step 4: Convert IFC model objects to appropriate RFEM model objects
await RfemApp.convert_objects(
convertInto: Common.ConvertObjectInto.ConvertIfcObjectIntoStraightMember,
objs: members
);
await RfemApp.convert_objects(
convertInto: Common.ConvertObjectInto.ConvertIfcObjectIntoSurface,
objs: surfaces
);
await RfemApp.convert_objects(
convertInto: Common.ConvertObjectInto.ConvertIfcObjectIntoSolid,
objs: solids
);
}
catch (Exception ex)
{
Console.WriteLine($"Error: {ex.Message}");
}
finally
{
if (RfemApp != null) await RfemApp.close_connection();
}