In Exporting DWG to SDF using *.epf file using Map 3D API I showed how to use *.epf file and Map 3D API to export DWG file to SDF file. In this example, I tried to explore how we can export DWG data to SDF (Spatial Data File) using AutoCAD Map 3D API without using a *.epf file. This sample code uses Map 3D Autodesk.Gis.Map.ImportExport.Exporter class and exports the entities from a specific layer in the DWG file to GeometryType.Line. To find out what all GeometryType you can export, you need to explore the Autodesk:: Gis:: Map:: ImportExport:: GeometryType Enumeration. Details of these are available in the Map 3D SDK API reference documents. Here is the code snippet :
Editor ed = Application.DocumentManager.MdiActiveDocument.Editor;
try
{
Exporter myExporter = null;
MapApplication mapApp = HostMapApplicationServices.Application;
myExporter = mapApp.Exporter;
myExporter.Init("FDO_SDF", @"C:\Temp\Test.sdf");
myExporter.ClassMappingType = ExportClassMappingType.ByLayer;
myExporter.ClosedPolylinesAsPolygons = true;
string sSourceName = "Line"; // Source DWG file should have a Layer Named "Line"
string sSchemaName = "ADNSchema";
string sFeatureClassName = "LineFC";
ExportClassMapping mapping = ExportClassMapping.Create(sSourceName, sSchemaName, sFeatureClassName);
mapping.AddPropertyMapping(".COLOR", "Color");
mapping.AddPropertyMapping(".LAYER", "Layer");
mapping.AddPropertyMapping(".LENGTH", "Length");
myExporter.AddClassMapping(mapping);
myExporter.SetGeometryTypeForClass(sSchemaName, sFeatureClassName, GeometryType.Line);
myExporter.TargetCoordinateSystem = "LL84";
myExporter.ExportAll = true;
myExporter.Export(true);
ed.WriteMessage("\nExport Completed !");
}
catch (Autodesk.Gis.Map.MapImportExportException e)
{
ed.WriteMessage("Exception thrown. Error Code = " + e.ErrorCode);
}
And here is the resulted output SDF file in Map 3D :