Drawings SDK supports import from .dgn files to .dwg files by providing the DGN import TX module:
TD_DgnImport_x.yysrc_zz.tx
where:
The DGN import module exposes the interface for converting .dgn files to .dwg files.
The module exposes a single interface, which serves as a class factory for OdDgnImport objects. An instance of the OdDgnImport class (an importer) does the conversion.
The DGN import TX module is a single support module for the Drawings SDK, and it's available in dynamic and static forms for Windows, Linux, and macOS (x86 and x64 versions). All source is available in the release packages.
For dynamic (.dll) configurations, the DGN import TX module can be loaded dynamically; it does not need to be linked to. For static configurations, the DGN import module should be linked to.
DGN Import supports the following features:
Drawings SDK uses three approaches for importing DGN content:
Most DGN import of elements is implemented with the Protocol Extension approach. If there is no custom Protocol Extension for an element, the default Protocol Extension is used, which explodes geometry to simplify DGN elements before importing.
In the case of using a custom Protocol Extension approach, a particular Protocol Extension class must be created for each element of the DGN model. Such Protocol Extension classes should be inherited from the OdDgnImportPE class with custom implementation of the importElement() method.
The following picture illustrates how the DGN import technology is implemented through Protocol Extensions.
For detailed information about supported DGN elements, see DGN Elements Available for Import to .dwg Files .
Importing process contains several stages:
A property map is used for storing import parameters. The following parameters are the most important:
For a complete list of input parameters, see DGN Import Parameters.
The importer may fail and return an error code from the “ImportResult” enumeration. The supported codes are:
Identifier | Error description |
---|---|
success | Import was finished successfully. |
bad_password | Currently not supported, will be used when encryption support is added to Drawings SDK for .dgn files. |
bad_file | Import failed: Wrong format of the imported .dgn file. The file is probably not a .dgn file. |
bad_database | Import failed: The file is a .dgn file, but there is something wrong with the database structure. |
encrypted_file | Import failed: The file is password protected (there is no current support for decryption). |
If the import result was “success”, the imported .dwg file database may be obtained from the importer property map under the “Database” key. Most of the objects in a .dgn file directly correspond to objects in the imported .dwg file database (the file structures are very similar).
// Load DGN import TX module
OdDgnImportModulePtr pModule = ::odrxDynamicLinker()->loadApp(OdDgnImportModuleName, false);
// Create an importer instance
OdDgnImportPtr importer = pModule->create();
// Set host application services object (to create new database, etc.)
importer->properties()->putAt(L"Services", pHostApp);
// Set the path to be imported (in-memory streams are not supported yet)
importer->properties()->putAt(L"DgnPath", OdRxVariantValue(path));
// Do the importing
OdDgnImport::ImportResult res = importer->import();
// Check that the result code is ok
if (res != OdDgnImport::success)
throw res;
// Retrieve the imported DWG database
OdDbDatabasePtr pDb = importer->properties()->getAt(L"Database");
Another way to create a DGN importer is to use the createDgnImporter() function (from TD_DGN_IMPORT namespace):
OdDgnImportPtr importer = createDgnImporter();
if (importer.isNull())
{
odPrintConsoleString(L"Could not create dgn importer\n");
}
To create a custom Protocol Extension, inherit the OdDgnImportPE class and re-implement the importElement() method.
struct OdDgCustomDefinedImportPE : OdDgnImportPE
{
void importElement(OdDgElement* e, OdDbBlockTableRecord* owner) ODRX_OVERRIDE
{
// Create a dwg entity and convert dgn data to it
// ...
// Append the dwg entity to owner
}
}
Then it is necessary to modify registerElementLoaders() and unregisterElementLoaders() for the DgnImporter class:
void DgnImporter::registerElementLoaders( OdDbHostAppServices* pHostAppServices )
{
// ...
// Add your code to the end
static OdStaticRxObject dgComplesStringImp;
OdDgComplexString::desc()->addX(OdDgnImportPE::desc(), &dgComplesStringImp);
}
void DgnImporter::unregisterElementLoaders( OdDbHostAppServices* pHostAppServices )
{
// ...
// Add your code here
OdDgComplexString::desc()->delX(OdDgnImportPE::desc());
// ...
}
Drawings SDK provides the ExDgnImport sample application which shows how to use DGN import functionality in user applications. ExDgnImport is a console application that implements working with DGN import functionality.
To run the application, use the following usage syntax: ExDgnImport <source_dgn_file> <target_dwg_file>.
Source files for the ExDgnImport application are located in Drawing/Examples/ExDgnImport.
DGN Elements Available for Import to .dwg Files
Working with Other File Formats
Copyright © 2002 – 2021. Open Design Alliance. All rights reserved.
|