Exporting DWG to SDF using *.epf file using Map 3D API

By Partha Sarkar

Want to export a DWGTM file with Map 3D Object Data to a SDF file using .NET API? Autodesk.Gis.Map.ImportExport.Exporter API class has the required functionality to enable this export. However, in the past we had found some issues with it and the resultant export was not producing expected SDF file. With the release of AutoCAD® Map 3D 2012 SP1 exporting DWG to SDF using *.epf file through Autodesk.Gis.Map.ImportExport.Exporter API class is now operational.

Make sure to reference the ManagedMapApi.dll (C:Program FilesAutodeskAutoCAD Map 3D 2012ManagedMapApi.dll) to your project. 

Here is a .NET code sample which demonstrates how to export a DWG file with Map 3D Object Data to a SDF file using Autodesk.Gis.Map.ImportExport.Exporter API – 

// AutoCAD Ref
using Autodesk.AutoCAD.Runtime;
using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.DatabaseServices;
 
// Map 3D Ref
using map = Autodesk.Gis.Map; 
 
namespace MapExport
{
    public class Class1
    {
        public static Autodesk.AutoCAD.EditorInput.Editor Editor
        {
            get
            {
                return Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor;
            }
        }
 
        [CommandMethod("ADN_EXPORTSDF")]
        static public void ExportSDFTest() // This method can have any name
        {
            try
            {
 
                map.ImportExport.Exporter exporter = map.HostMapApplicationServices.Application.Exporter;
                exporter.Init("FDO_SDF", "C:\Temp\Street_Centerlines.sdf");
                exporter.LoadExportFormat("C:\Temp\Street.epf");
                exporter.Export();
 
                DisplayOutputMessage(string.Format("Export completed."));
            }
            catch (map.MapException ex)
            {
                map.Constants.ErrorCode errOdCode = (map.Constants.ErrorCode)ex.ErrorCode;
                MessageBox.Show("The following Map exception has occurred:nn" + errOdCode);
            }
            catch (System.Exception ex)
            {
                MessageBox.Show("The following exception has occurred:nn" + ex.ToString());
            }
        }
 
        static void DisplayOutputMessage(String str)
        {
            Editor.WriteMessage(str);
 
        }
 
    }
}

Comments

Leave a Reply

Discover more from Autodesk Developer Blog

Subscribe now to keep reading and get access to the full archive.

Continue reading