Export DWG to SDF using Autodesk.Gis.Map.ImportExport.Exporter API

By Partha Sarkar

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:TempTest.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 :

DWG_2_SDF


Comments

10 responses to “Export DWG to SDF using Autodesk.Gis.Map.ImportExport.Exporter API”

  1. Hi,
    you know if is possible to do something similar but from Autodesk Infraestructure Map Server? Maybe with AIMS Studio API???
    Thanks

  2. Hi Andres,
    AIMS is designed to serve Map online. If you are looking for a way to upload DWG file to AIMS server you can use Infrastructure Studio API. Infrastructure Studio has DwgLoadProcedure which we can use to load DWG files to AIMS server.
    Does this info help ?
    Thanks,
    Partha
    A D N

  3. mehrsa rad Avatar
    mehrsa rad

    hi Partha, i’ve used your code to load ipf into shape files while importing
    but there’s a problem, i have multiple shape files, and select theme in the “import location” dialogue
    importer.Init(“SHP”, “d:\files\CAD\GIS_EXPORT_1391128_135103\ISELFCT.shp”);
    importer.LoadImportFormat(“d:\files\CAD\Imp_Attribute_910809.ipf”);
    the ipf file loads just in one of my shape file that is given in init
    what should i do to load ipf in all shapes which i select to import?
    thank u in advance

  4. Hi Partha,
    I tried this code to get the layers from the current drawing how about the xref layers, how will i be able to get the layers from the current and xref then create a single sdf file?
    Thanks,
    Sherwin

  5. Hi Partha,
    I use your code to export current layers of the drawing to sdf but how do i get the xref layers also?
    Thanks an Regards,
    Sherwin

  6. Hi Partha
    Do you have example of export to sdf using Exporter.LayerFilter?

  7. Sherwin Avatar
    Sherwin

    Is there an API for exporting the SDF to version 2 instead of version 3?

  8. Hi Sherwin,
    AFAIK there is no API to export to old SDF i.e. ‘SDF2’ for old MapGuide 6.5 or earlier.
    You need to use either MAP2SDF UI tool / command in AutoCAD Map 3D or you can use SDF Loader.
    SDF Loader is included in SDF ToolKit, and it can be downloaded from http://usa.autodesk.com/adsk/servlet/ps/dl/item?siteID=123112&id=4307350&linkID=9240658
    Thanks,
    Partha

  9. Hi Partha,
    is it possible to do the code above in vlisp/activx
    (the code to create an sdf file from map 3d or using
    only autocad 14) and if possible, can you provide a sample.
    thanks
    m

  10. Hi Mark,
    No, these APIs are not exposed in LISP / ActiveX.
    Thanks,
    Partha

Leave a Reply

Discover more from Autodesk Developer Blog

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

Continue reading