Import & export
IFC
ALLPLAN Python API offers two classes with methods for handling IFC files:
Each of them works in a slightly different way and return different kind of objects. Choosing the most suitable will often depend on the use case.
IFC import
Using Cad Data File Reader
The static method ReadIFC can read the data from an IFC file. It only reads the IFC data and returns it organized into groups represented by tuples containing:
- the group name and
- list of ModelElement3D objects belonging to this group
The method only reads the data and returns the ModelElement3D objects. It does not create them in the DF. The objects can be processed further e.g. be added to a PythonPart and placed at a point, along a path or in a grid. This makes it the best import method for IFC files containing subordinate objects, like fixtures.
ifc_data = AllplanBaseElements.CadDataFileReader.ReadIFC(document_adapter, ifc_file_path)
model_element_list = [model_element for group_name, model_element_group in ifc_data for model_element in model_element_group] #(1)!
- We can flatten the data structure returned by the ReadIFC method to just one simple list containing all ModelElement3D objects from the IFC file by a two-step list comprehension.
Warning
The ReadIFC can read only specific type of IFC entities from an IFC file! I.e. it will read only the BuildingElementProxy objects and group them based on which ElementAssembly they belong to.
Example on GitHub
Complete implementation of the CadDataFileReader class is shown in the example CadDataFileReader ( PYP | PY)
Using Import Export Service
The method ImportIFC reads the data from IFC file and directly creates model elements in the specified DF. It also returns the BaseElementAdapterList with adapters to the created objects, so that they still can be accessed later in the script.
export_import_service = AllplanBaseElements.ExportImportService() #(1)!
imported_elements = export_import_service.ImportIFC( \
doc= document_adapter,
fileNumber= drawing_file_number,
fileName= ifc_file_path)
- Note that you must instantiate the service first.
Tip
This method can be considered as the equivalent for the ALLPLAN feature Import IFC data. It is the best method to IFC file containing an entire AEC project e.g., a whole building structure.
IFC export
The method ExportIFC can be used to export IFC data from specified DFs and save it as IFC file into a desired location. The function call look like this:
export_import_service = AllplanBaseElements.ExportImportService() #(1)!
export_import_service.ExportIFC( \
doc= document_adapter,
fileNumbers= export_file_numbers,
ifcVersion= AllplanBaseElements.IFC_Version.Ifc_4, #(2)!
fileName= ifc_file_path,
ifcThemeFileName= ifc_export_theme_file) #(3)!
- Note that you must instantiate the service first.
- See the enumeration class IFC_Version for more options.
- Path to a theme file may optionally be provided. A theme file has a .nth extension and contains all settings for an IFC export. It can be created directly in ALLPLAN, using Export IFC data. Default files are provided in ...\etc\Favorites - standard\Ifc\
SKP
The SketchUp files can be read using the method ReadSKP. The method reads the data from the file and returns a flat Python list of ModelElement3D objects, which can be processed further in the script e.g., be added to a PythonPart and placed at a point, along a path or in a grid.
model_ele_list = AllplanBaseElements.CadDataFileReader.ReadSKP(
skp_file_path,
AllplanBaseElements.eDesignPathLocation.OverrideFiles
)
- Provide an absolute path to the .skp file
OBJ
The Wavefront OBJ file format is a simple data-format that represents 3D geometry alone, first developed by Wavefront Technologies. The elements are read from file by using ReadOBJ. Just as ReadSKP, this method will return a list of ModelElement3D objects, which can be processed further.
model_ele_list = AllplanBaseElements.CadDataFileReader.ReadSKP(
skp_file_path, #(1)!
AllplanBaseElements.eDesignPathLocation.OverrideFiles
)
- Provide an absolute path to the .obj file