Import-Export Detail

AutoCAD Map 3D ObjectARX

 
Import-Export Detail
 
 
 

By importing a map, you can combine data from other mapping or GIS programs by importing the data into AutoCAD Map 3D. You can import the map objects themselves, and the data and display options associated with them. In addition, you can specify an import area to determine which area of the map will be imported, assign incoming objects to existing feature classes, and automatically perform a coordinate conversion on the objects as they are imported.

By exporting a map, you can export data to an external file format. You can export the map objects themselves, and the data associated with them, and specify that AutoCAD Map 3D performs a coordinate conversion on the objects automatically as they are exported.

Use profiles to save your import and export settings in a profile to automate the process of importing and exporting files. You can save and load import profile files (.ipf) or export profile files (.epf).

The following file formats are supported for both import and export, unless otherwise indicated:

  • ArcView ShapeFile (also called ESRI ShapeFile or ESRI Shape)
  • ArcInfo Coverages and E00
  • GML (Geography Markup Language) version 2
  • GML (Geography Markup Language) version 2, Ordinance Survey of Great Britain MasterMap (import only)
  • MapInfo MIF/MID
  • MapInfo TAB
  • MicroStation DGN versions 7 and 8
  • SDTS (Spatial Data Transfer Standard) (import only)
  • VML (Vector Markup Language) (export only)
  • VPF (Vector Product Format) (import only)

See also Other Information Sources.

Importing Maps Setting Import Options Exporting Maps Setting Export Options Using Reactors with Export and Import Events Using Iterators Handling Errors Other Information Sources Import-Export Samples Import-Export Classes, Namespaces, and Globals

Importing Maps

To import an file to an AutoCAD Map 3D drawing, perform the following steps, as shown in the sample code that follows:

  1. Retrieve the Autodesk Map importer object, an AcMapIEImporter singleton instance, by calling the global function AcMapImporter().
  2. Initialize the importer with Init(). (You must call Init() before you call any other AcMapIEImporter functions.)

    Init() requires an AcMapIEFormat name that specifies the format of the incoming file.

  3. Optionally, add reactors to the importer.
  4. Set the import options.

    -or-

    Use LoadIPF() to load previously saved import settings from a profile (.ipf) file. (You can save the current import options in a profile file with SaveIPF().)

  5. Call Import() to perform the import.

    Import results are stored in an AcMapIE::CImportResults struct.

For import-export source-code samples, see Import-Export Samples.

      
AcMapIE::ErrCode errCode;
      
// Retrieve the AutoCAD Map 3D importer object.
AcMapIEImporter* pImporter = AcMapImporter();
      
// Initialize the importer.
char* pszFormat = "MIF"; // Name of an AcMapIEFormat.
char* pszImpFileName = "C:\\temp\\my_import_file.mif"; 
errCode = pImporter->Init(pszFormat, pszImpFileName);
if (errCode != AcMapIE::kErr_OK)
{
// Handle the error.
}
      
// Get an iterator over the layers in the imported file.
AcMapIEInputLayerIterator* pInputLayers;
errCode = pImporter->InputLayerIterator(pInputLayers); 
if (errCode != AcMapIE::kErr_OK)
{
// Handle the error.
}
      
// Iterate over each layer.
for (pInputLayers->Rewind(); !pInputLayers->Done(); pInputLayers->Step())
{
AcMapIEInputLayer* pLayer = NULL;
if(pInputLayers->Get(pLayer) == false)
{
// Handle the error.
}
      
// Import attribute data from the import file to the
// new object-data table in the Autocad Map drawing.
      
// Insert code to set the table type and table name 
// with AcMapIEInputLayer::SetDataMapping()
// and set the feature class name
// with AcMapIEInputLayer::SetFeatureClassName(). 
      
// Set column mappings.
AcMapIEColumnIterator* pColumns = pLayer->ColumnIterator();
if(pColumns)
{
for (pColumns->Rewind(); !pColumns->Done(); pColumns->Step())
{
// Insert code to set column data mappings 
// with AcMapIEColumn::SetColumnDataMapping()
// and set column feature-class mappings 
// with AcMapIEColumn::SetColumnClassMapping().
}
delete pColumns;
}
delete pLayer;
}
delete pInputLayers;
      
// Perform the import and get the results.
AcMapIE::CImportResults results;
bool bUseProgressDialog = false;
errCode = pImporter->Import(results, bUseProgressDialog);
if(errCode != AcMapIE::kErr_OK)
{
// Handle the error.
} 
      
// Process or log the import results, if desired.

Back to top

Setting Import Options

When importing a drawing into AutoCAD Map 3D, you can set import options for each incoming layer. AcMapIEImporter::InputLayerIterator() retrieves an iterator over all imported layers; each layer is an AcMapIEInputLayer instance, named Name(). Use the following AcMapIEInputLayer functions to set and retrieve layer-level import options:

On each layer, you can set individual mappings from each incoming column to a target column in AutoCAD Map 3D. AcMapIEInputLayer::ColumnIterator() retrieves an iterator over a layer's columns; each column is an AcMapIEColumn instance, named ColumnName(). You can define two types of column mappings, provided that you already have set the column's data table and feature class with AcMapIEInputLayer::SetDataMapping() and AcMapIEInputLayer::SetFeatureClassName():

You also can use the following AcMapIEImporter functions to set and retrieve high-level import options:

For import-export source-code samples, see Import-Export Samples.

Back to top

Exporting Maps

To export an AutoCAD Map 3D drawing, perform the following steps, as shown in the sample code that follows:

  1. Retrieve the Autodesk Map exporter object, an AcMapIEExporter singleton instance, by calling the global function AcMapExporter().
  2. Initialize the exporter with Init(). (You must call Init() before you call any other AcMapIEExporter functions.)

    Init() requires an AcMapIEFormat name that specifies the target file format. You can use FormatName() to retrieve the format name at any time after initialization.

  3. Optionally, add reactors to the exporter.
  4. Set the export options.

    -or-

    Use LoadEPF() to load previously saved export settings from a profile (.epf) file. (You can save the current export options in a profile file with SaveEPF().)

  5. Call Export() to perform the export.

    Export results are stored in an AcMapIE::CExportResults struct.

For import-export source-code samples, see Import-Export Samples.

      
AcMapIE::ErrCode errCode;
      
// Retrieve the AutoCAD Map 3D exporter object.
AcMapIEExporter* pExporter = AcMapExporter();
      
// Initialize the exporter.
char* pszFormat = "MIF"; // Name of an AcMapIEFormat.
char* pszExpFileName = "C:\\temp\\my_export_file.mif"; 
errCode = pExporter->Init(pszFormat, pszExpFileName);
if (errCode != AcMapIE::kErr_OK)
{
// Handle the error.
}
      
// Insert code to set filter, data mapping, 
// and other <a href="#export_options">export options</a>.
      
// Perform the export and get the results.
AcMapIE::CExportResults results;
bool bUseProgressDialog = false;
errCode = pExporter->Export(results, bUseProgressDialog);
if (errCode != AcMapIE::kErr_OK)
{
// Handle the error.
}
      
// Process or log the export results, if desired.

Back to top

Setting Export Options

Use export options to control which objects in the current drawing are exported by applying a layer filter, feature-class filter, and selection set. (CountObjects() counts the number and type of entities to export.) You also can set storage options, driver options, data mappings, and other options. Use the following AcMapIEExporter functions to set and retrieve export options:

For import-export source-code samples, see Import-Export Samples.

Back to top

Using Reactors with Export and Import Events

TheAcMapIEExportReactorandAcMapIEImportReactorreactor classes provide callback functions that notify an application immediately of export and import events. You can use these mechanisms to monitor or control export and import operations by adding reactor instances. Functions are invoked automatically depending on the stage of the operation, as described in the following tables:

Export reactor function Invoked
RecordError() If an error occurs during export
RecordExported() After an entity is exported
RecordReadyForExport() Before an entity is exported
Import reactor function Invoked
RecordError() If an error occurs during import
RecordImported() After an entity is imported
RecordReadyForImport() Before an entity is imported

You can add or remove export reactors with AcMapIEExporter::AddReactor() or AcMapIEExporter::RemoveReactor(), and add or remove import reactors with AcMapIEImporter::AddReactor()or AcMapIEImporter::RemoveReactor(). To use a reactor, perform the following steps, as shown in the sample code that follows:

  1. Derive a custom class from AcMapIEExportReactor or AcMapIEImportReactor.
  2. Implement events by overriding the virtual functions that you need.
  3. Create an instance of the custom reactor.
  4. Add the instance so that it becomes active.
  5. Write some export or import reactor code.
  6. Remove the reactor and delete it.

For import-export source-code samples, see Import-Export Samples.

      
// Derive a custom class from AcMapIEExportReactor.
class AcMapIEMyExportReactor : public AcMapIEExportReactor
{
// Override virtual functions for the desired export events.
} ;
      
// Create an instance of the custom reactor.
AcMapIEMyExportReactor* pMyReactor = new AcMapIEMyExportReactor;
      
// Add the custom reactor.
AcMapIEExporter().AddReactor(pMyReactor);
      
// Insert export reactor code here.
      
// Remove the reactor and delete it.
AcMapIEExporter().RemoveReactor(pMyReactor);
delete pMyReactor; 

Back to top

Using Iterators

The following table lists the iterator classes, which provide iterators over collections of objects that import-export functions return or take. The AcMapIEExpressionTargetIteratorand AcMapIENameValueIteratorclasses allow you to modify the iterator's underlying collection by adding, updating, and deleting elements, whereas the other classes iterate over fixed collections. The global functionsAcMapExportFormatIterator()andAcMapImportFormatIterator()return the export-format and import-format iterators, respectively.

Class Iterates over a collection of
AcMapIEColumnIterator AcMapIEColumn instances
AcMapIEExpressionTargetIterator Expression-target pairs
AcMapIEFormatIterator AcMapIEFormat instances
AcMapIEInputLayerIterator AcMapIEInputLayer instances
AcMapIENameValueIterator Name-value pairs

For import-export source-code samples, see Import-Export Samples.

Back to top

Handling Errors

Many functions in the various import-export classes return an AcMapIE::ErrCode error code. When a particular function returns an error code, read that function's documentation for function-specific error conditions rather than relying on only the generic error descriptions in the AcMapIE::ErrCode documentation.

Back to top

Other Information Sources

  • For more information about importing and exporting maps in AutoCAD Map 3D, choose Help &gt; AutoCAD Map 3D Help &gt; Contents tab (or press F1), and then navigate to Using AutoCAD Map 3D (by feature) &gt; Importing and Exporting Maps.
  • For an import-export tutorial in AutoCAD Map 3D, choose Help &gt; Tutorials &gt; Contents tab, and then choose "Importing and Exporting Data".

Back to top

Import-Export Samples

To view code samples of import-export functions, open the Samples folder in your AutoCAD Map 3D ObjectARX installation and navigate to Map Samples\ImportExport.

Back to top