Use the DWF import TX module to import from Design Web Format (DWF) .dwf and .dwfx files to .dwg or .dxf files:
TD_Dwf7Import_xx.yy_zz.tx
where:
The module exposes a single interface, which serves as a class factory for OdDwfImport objects. An instance of the OdDwfImport class (an importer) does the conversion.
The DWF 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 DWF import TX module can be loaded dynamically; it does not need to be linked to. For static configurations, the DWF import module should be linked to.
There are two abstract classes that can be inherited by classes that implement their own algorithm of DWF import: OdDwfImport and OdDwfImportModule.
The import process commonly consists of five steps:
Prior to following the steps from the above list, some preliminary actions must be performed, including creating a custom services object and initializing it:
// Create a custom Services object.
OdStaticRxObject svcs;
// Initialize ODA Platform.
odInitialize(&svcs);
For DWF import module creation, the method loadModule() of the odrxDynamicLinker object must be called. The loadModule() method returns a smart pointer to the import module (import module object is an instance of the class inherited from the OdDwfImportModule class). Then call the create() method of the import module object to get a smart pointer to the importer instance (an instance of the class inherited from OdDwfImport).
// Load the DWF import TX module
OdDwfImportModulePtr pModule = ::odrxDynamicLinker()->loadApp(OdDwf7ImportModuleName, false);
// Create an importer instance
OdDwfImportPtr importer = pModule->create();
Additionally, the function createImporter() defined in the TD_DWF_IMPORT namespace can be used for creation of the DWF importer object. When using this function, there is no need to create a DWF import module because createImporter() creates it by itself.
#include "DwfImport.h"
using namespace TD_DWF_IMPORT;
// Create an importer instance
OdDwfImportPtr importer = createImporter();
There are several import parameters that must be set for importing DWF (.dwf or .dwfx) files:
The following code creates an instance of the OdDbDatabase class and puts a pointer to it in the pDb variable. This pointer will be used for setting up a "Database" parameter.
// Create an instance of OdDbDatabase class and get a pointer to it
OdDbDatabasePtr pDb = svcs.createDatabase();
Parameters are set by defining the corresponding properties of the importer object:
// Set the import parameters
importer->properties()->putAt(L"Database", pDb);
importer->properties()->putAt(L"DwfPath", OdRxVariantValue(OdString(inputFileName)));
importer->properties()->putAt(L"Password", OdRxVariantValue(OdString::kEmpty));
importer->properties()->putAt(L"PreserveColorIndices", OdRxVariantValue(true));
importer->properties()->putAt(L"LayoutNumber", OdRxVariantValue(OdInt32(-1)));
importer->properties()->putAt(L"ImportW3d", OdRxVariantValue(true));
After the properties are set, the .dwf/.dwfx file can be imported using the import() method:
// Import DWF file
TD_DWF_IMPORT::OdDwfImport::ImportResult impRes = importer->import();
And finally, analysis of the result. The impRes variable is of the ImportResult type which is an enumeration with the following values:
Identifier | Error description |
---|---|
success | Import finished successfully. |
fail | Import failed: Internal import error. |
bad_password | Import failed: Wrong password for the imported .dwf/.dwfx file. |
bad_file | Import failed: Wrong format of the imported .dwf/.dwfx file. |
bad_database | Import failed: Invalid database pointer or corrupted database. |
encrypted_file | Import failed: Imported .dwf/.dwfx file is protected. |
The "encrypted_file" import result arises when an object of the kzMIMEType_W3D_S MIME type is detected during the import process. This means that the imported .dwf/.dwfx file is protected. For more details, follow the link.
If the import result was "success", the imported database can be accessed for further operations, for example, saving it as a .dwg file:
if(impRes == TD_DWF_IMPORT::OdDwfImport::success) {
// The importer object is not needed anymore
importer = 0;
// Create a write file buffer and link it with the output file
OdWrFileBuf fb(OdString(outputFileName));
// Get the extension of the output file to determine its type
OdString ext = outputFileName.right(4);
ext.makeUpper();
// Write the database to the file taking into account the file type
if ( ext == L".DWG" )
pDb->writeFile(&fb, OdDb::kDwg, OdDb::kDHL_CURRENT);
else if ( ext == L".DXF")
pDb->writeFile(&fb, OdDb::kDxf, OdDb::kDHL_CURRENT);
}
The OdDwfImportEx sample application shows how to use DWF import functionality in user applications. OdDwfImportEx is a console application that implements working with DWF import functionality.
To run the application, use the following syntax:
OdDwfImportEx <input_file><output_file>where:
Source files for the OdDwfImportEx application are located in the Drawing/Examples/OdDwfImportEx folder.
Copyright © 2002 – 2021. Open Design Alliance. All rights reserved.
|