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
export module:
Ifc2Dwg.tx
.
Exchange/Exports/Ifc2Dwg
.
The functionality of the Ifc2Dwg
module can be used within the
OdaMfcApp sample application for both dynamic and static configurations.
The functionality of the Ifc2Dwg
module is based on the pure abstract class
OdIfcExport
.
The IfcExporter
class is derived from it and provides two methods that allow you to run the export process:
OdRxDictionaryPtr properties()
—
Provides access to the export process properties which are stored in a dictionary object.
ExportResult exportIfc()
—
Runs the export with specified properties.
This method returns a value of the ExportResult
enumeration which contains the export result code.
All export parameters are divided into two groups:
The table below contains the list of conversion parameters and their descriptions.
Parameter Name | Parameter Type | Parameter Description |
---|---|---|
IfcFilePath
|
Input | The full path to an IFC file to be converted to .dwg (for example, "d:\files\ifc_to_dwg.ifc"). |
OdDbServices
|
Input | A smart pointer to a host application services object that can create a new drawing database. |
IfcServices
|
Input | A smart pointer to a host application services object that implements the processing of IFC file content. If the smart pointer is not set, the default IFC SDK application service implementation is used. If the default application service object is used, the user cannot control conversion properties. |
ExportBuildingElementProxy
|
Input |
A flag that defines whether IfcBuildingElementProxy geometry should be converted to .dwg structures (if equal to true)
or not (if equal to false). If the flag equals false, IfcBuildingElementProxy geometry objects are skipped during the
conversion procedure.
|
ZoomExtents
|
Input |
A flag that determines whether the view of the resulting OdDbDatabase object
should be zoomed to the converted geometry (if equal to true) or not (if equal to false).
|
ExportMode
|
Input |
An ExportMode enumeration value that defines the type of geometry conversion.
|
Database
|
Output |
A smart pointer to the resulting OdDbDatabase
with the converted geometry.
|
IfcFile
|
Output |
A smart pointer to the OdIfcFile object (a database of entities) that represents the source IFC file.
Can be used together with the ConnectionMap property for mapping between
OdDbEntity objects and IFC instances.
|
IfcConnectionMap
|
Output |
A map object that contains pairs of OdDbObjectId
and OdDAIObjectId instances.
This map stores connections between input IFC instances and exported drawing database entities.
|
Include the following headers and namespace instructions:
#include "Common/ModuleNames.h"
#include "../Exchange/Exports/Ifc2Dwg/Include/IfcExport.h"
For static configurations, use the set of DECLARE/DEFINE_STATIC
macro instances:
//
// Define module map for statically linked modules:
//
#if !defined(_TOOLKIT_IN_DLL_)
ODRX_DECLARE_IFC2DWG_STATIC_MODULES_ENTRY_POINTS()
ODRX_DECLARE_STATIC_MODULE_ENTRY_POINT(OdRecomputeDimBlockModule);
ODRX_DECLARE_STATIC_MODULE_ENTRY_POINT(OdRxThreadPoolService);
ODRX_BEGIN_STATIC_MODULE_MAP()
ODRX_DEFINE_IFC2DWG_STATIC_APPMODULES()
ODRX_DEFINE_STATIC_APPMODULE(OdRecomputeDimBlockModuleName, OdRecomputeDimBlockModule)
ODRX_DEFINE_STATIC_APPMODULE(OdThreadPoolModuleName, OdRxThreadPoolService)
ODRX_END_STATIC_MODULE_MAP()
#endif
The set of supported schema-dependent modules for Ifc2x3, Ifc4 etc. can vary. If support for other precompiled (or generated/compiled by a user) schemas is needed,
they need to be added as a set of STATIC macros, as in CMakelists.txt
.
To use the export functionality in your IFC SDK based application:
Ifc2Dwg
export module and check whether it is available (i.e., the module is successfully loaded):
OdIfc2DwgModulePtr pIfc2DwgModule = ::odrxDynamicLinker()->loadApp(OdIfc2DwgModuleName, false);
if (!pIfc2DwgModule.isNull())
{
//Add code here to set export properties and run the export process (see the next steps for details)
}
ifc2Dwg
module loading (see the previous step for details):
if (!pIfc2DwgModule.isNull())
{
OdIfcExportPtr Exporter = pIfc2DwgModule->create();
Exporter->properties()->putAt(L"OdDbServices", static_cast(&dbSvcs));
Exporter->properties()->putAt(L"IfcServices", static_cast(&ifcSvcs)); // Optional
Exporter->properties()->putAt(L"IfcFilePath", OdRxVariantValue(ifcInFileName));
Exporter->properties()->putAt(L"ExportBuildingElementProxy", OdRxVariantValue(true));
Exporter->properties()->putAt(L"ZoomExtents", OdRxVariantValue(true));
Exporter->properties()->putAt(L"ExportMode", OdRxVariantValue(OdInt16(TD_IFC_EXPORT::kAsPolyFaceMesh)));
}
OdPerfTimerWrapper timerWrapper;
timerWrapper.getTimer()->start();
// Start conversion
OdIfcExport::ExportResult res = Exporter->exportIfc();
timerWrapper.getTimer()->stop();
odPrintConsoleString(L"\nIfc2Dwg: ifc reading time is %d msec", timerWrapper.getTimer()->countedMSec());
OdDbDatabasePtr pDb;
if (res == OdIfcExport::success)
{
odPrintConsoleString(L"\nIfc2Dwg: successful conversion");
pDb = Exporter->properties()->getAt(L"Database"); // Created inside of Ifc2Dwg module if wasn't provided before.
OdRxObjectPtr pFile = Exporter->properties()->getAt(L"IfcFile");
OdIfcConnectionMapPtr pMap = Exporter->properties()->getAt(L"IfcConnectionMap");
OdRxObjectPtr pMapAssignedFile = pMap->getIfcFile();
ODA_ASSERT(pFile.get() == pMapAssignedFile.get());
if (!dwgOutFileName.isEmpty())
{
odPrintConsoleString(L"\nIfc2Dwg: writing .dwg file %s", dwgOutFileName.c_str());
pDb->writeFile(dwgOutFileName, OdDb::kDwg, OdDb::vAC32);
}
}
else
{
switch (res)
{
case OdIfcExport::bad_database:
odPrintConsoleString(L"\nIfc2Dwg: bad database\n");
break;
case OdIfcExport::bad_file:
odPrintConsoleString(L"\nIfc2Dwg: bad ifc file\n");
break;
case OdIfcExport::fail:
odPrintConsoleString(L"\nIfc2Dwg: unknown conversion error\n");
break;
}
}
The resulting OdDbDatabase
will contain a set of OdDbBlockReference
and OdDbBlockDefinition
items with the appropriate names taken from the source IFC file
and the imported geometry inside of those block definitions.
The illustrations below show a drawing database exported from an IFC file of the IFC4x2 schema opened in the OdaMfcApp sample application.
openFile()
method in the
CommonApplications\Drawing\Examples\win\OdaMfcApp\OdaMfcApp.cpp
source file.
The example code is located under the #ifdef IFC2DWG_SUPPORT
precompiler instruction.
Copyright © 2002 – 2022. Open Design Alliance. All rights reserved.
|