ODA IFC SDK Developer's Guide > Export IFC to a .dwg Database
Export IFC Content to a .dwg Database

Export IFC content to a Drawing Database Support

IFC SDK provides functionality for exporting the content of an IFC file into a specified drawing database (a .dwg file). This functionality is implemented within the Ifc2Dwg exporting module:

  • Binary library: Ifc2Dwg.tx.
  • Source Code Location: Ifc/Exports/Ifc2Dwg.

The functionality of the Ifc2Dwg module can be used within the OdaMfcApp sample application provided by ODA for both dynamic static configurations.

The functionality of the Ifc2Dwg export module is based on the pure abstract class OdIfcExport. The IfcExporter class is derived from it and provides two methods that allow run the exporting process:

  • OdRxDictionaryPtr properties() — that provides access to the exporting process properties, stored in a dictionary object.
  • ExportResult exportIfc() — that runs the export with specified properties.

Export Procedure

To use the export functionality in your IFC SDK based application, you need to follow the procedure described below.

For dynamic configurations, it is needed to include the following headers and namespace usage instructions:

      
#ifdef IFC2DWG_SUPPORT
  #include "../Ifc/Include/Common/ModuleNames.h"
  #include "../Ifc/Exports/Ifc2Dwg/Include/IfcExport.h"
  using namespace TD_IFC_EXPORT;
#endif
            
    

For static configurations, use the set of DECLARE/DEFINE_STATIC macro instances:

      
#define ODRX_DECLARE_IFC2DWG_STATIC_MODULES_ENTRY_POINTS() \
  ODRX_DECLARE_STATIC_MODULE_ENTRY_POINT(OdSDAIModuleImpl); \
  ODRX_DECLARE_STATIC_MODULE_ENTRY_POINT(OdIfcCoreModule); \
  ODRX_DECLARE_STATIC_MODULE_ENTRY_POINT(OdIfc2x3Module); \
  ODRX_DECLARE_STATIC_MODULE_ENTRY_POINT(OdIfc4Module); \
  ODRX_DECLARE_STATIC_MODULE_ENTRY_POINT(OdIfc4x2Module); \
  ODRX_DECLARE_STATIC_MODULE_ENTRY_POINT(OdIfcGeomModuleImpl); \
  ODRX_DECLARE_STATIC_MODULE_ENTRY_POINT(OdIfcBrepBuilderModule); \
  ODRX_DECLARE_STATIC_MODULE_ENTRY_POINT(OdIfcFacetModelerModule); \
  ODRX_DECLARE_STATIC_MODULE_ENTRY_POINT(OdIfc2DwgModuleImpl);
// end of ODRX_DECLARE_IFC2DWG_STATIC_MODULES_ENTRY_POINTS macro

#define ODRX_DEFINE_IFC2DWG_STATIC_APPMODULES() \
  ODRX_DEFINE_STATIC_APPMODULE(OdSDAIModuleName, OdSDAIModuleImpl) \
  ODRX_DEFINE_STATIC_APPMODULE(OdIfcCoreModuleName, OdIfcCoreModule) \
  ODRX_DEFINE_STATIC_APPMODULE(OdIfc2x3ModuleName, OdIfc2x3Module) \
  ODRX_DEFINE_STATIC_APPMODULE(OdIfc4ModuleName, OdIfc4Module) \
  ODRX_DEFINE_STATIC_APPMODULE(OdIfc4x2ModuleName, OdIfc4x2Module) \
  ODRX_DEFINE_STATIC_APPMODULE(OdIfcGeomModuleName, OdIfcGeomModuleImpl) \
  ODRX_DEFINE_STATIC_APPMODULE(OdIfcBrepBuilderModuleName, OdIfcBrepBuilderModule) \
  ODRX_DEFINE_STATIC_APPMODULE(OdIfcFacetModelerModuleName, OdIfcFacetModelerModule) \
  ODRX_DEFINE_STATIC_APPMODULE(OdIfc2DwgModuleName, OdIfc2DwgModuleImpl)
// end of ODRX_DEFINE_IFC2DWG_STATIC_APPMODULES macro
      
    

The set of supported schema-dependent modules as Ifc2x3, Ifc4 etc. can varies, if support of other precompiled (or generated/compiled by user) schemas is needed, they definitely should be added as in set of STATIC macroses, as in CMakelists.txt.

The rest part of the export process can be described in the steps below;

  1. Load the Ifc2Dwg export module and check whether it is available (i.e. the module was successfully loaded):
              
    #ifdef IFC2DWG_SUPPORT
      if (!::odrxDynamicLinker()->loadApp(OdIfc2DwgModuleName, true).isNull())
        filter += _T("IFC files (*.ifc)|*.ifc|");
    #endif
              
            
  2. Run the export process:
              
    #ifdef IFC2DWG_SUPPORT
        else if (path.right(4).iCompare(L".ifc") == 0) // if trying to open an IFC file
        {
          OdIfc2DwgModulePtr pModule = ::odrxDynamicLinker()->loadApp(OdIfc2DwgModuleName, false);
          OdIfcExportPtr Exporter = pModule->create(); // create exporter from IFC to .dwg
    
    Following options are available for conversion:
    
          // The pointer to host app services that can create new OdDbDatabase
          Exporter->properties()->putAt(L"Services", static_cast(this));
    
          // An IFC file name with full path to convert into .dwg (like d:\files\ifc_to_dwg.ifc)
          Exporter->properties()->putAt(L"IfcFilePath", OdRxVariantValue(path));
    
          // The true value allows to convert IfcBuildingElementProxy geometry into .dwg structures, otherwise such objects will be skipped
          Exporter->properties()->putAt(L"ExportBuildingElementProxy", OdRxVariantValue(true));
    
          // View of resultant OdDbDatabase will be zoomed to converted geometry
          Exporter->properties()->putAt(L"ZoomExtents", OdRxVariantValue(true));
    
          // Import geometry as OdDbPolyfaceMesh, or import geometry as OdDbSubDMesh
          Exporter->properties()->putAt(L"ExportMode", OdRxVariantValue(OdInt16(TD_IFC_EXPORT::kAsPolyFaceMesh)));
    
          OdIfcExport::ExportResult res = Exporter->exportIfc(); // Process the conversion
    
          if (res == OdIfcExport::success)
          {
            pDb = Exporter->properties()->getAt(L"Database"); // Resultant OdDbDatabase with converted geometry
            OdRxObjectPtr pFile = Exporter->properties()->getAt(L"IfcFile"); // Smart pointer to OdIfcFile (database of entities) of source IFC file
            OdIfcConnectionMapPtr pMap = Exporter->properties()->getAt(L"IfcConnectionMap"); // Map between OdDbObjectId and OdDAIObjectId of IFC
            OdRxObjectPtr pMapAssignedFile = pMap->getIfcFile();
            ODA_ASSERT(pFile.get() == pMapAssignedFile.get()); // Smart pointer to OdIfcFile can be get from map if it was set as input parameter for exporter.
          }
          else
          {
            switch (res)
            {
            case OdIfcExport::bad_database:
              messageBox(_T("IFC import"), _T("Bad database"), MB_OK | MB_ICONERROR);
              break;
            case OdIfcExport::bad_file:
              messageBox(_T("IFC import"), _T("Bad file"), MB_OK | MB_ICONERROR);
              break;
            case OdIfcExport::fail:
              messageBox(_T("IFC import"), _T("Unknown import error"), MB_OK | MB_ICONERROR);
              break;
            }
          }
          pMFrame->StopTimer(_T("Loading"));
        }
    #endif
                        
            

The resultant OdDbDatabase will contain a set of OdDbBlockReferences to OdDbBlockDefinitions with appropriate names taken from the source IFC file and imported geometry inside of those BlockDefinitions.

At the illustrations below you can see a drawing database exported from a .ifc file of the IFC4x2 schema opened in the OdaMfcApp sample application.

See Also

IFC SDK Overview

Access to a Representation Body Geometry

Copyright © 2002 – 2020. Open Design Alliance. All rights reserved.