AutoCAD Map 3D Developer
Welcome to Autodesk’s AutoCAD Map 3D Developer Forums. Share your knowledge, ask questions, and explore popular AutoCAD Map 3D Developer topics.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Import ShapeFile into Autocad Map

0 REPLIES 0
Reply
Message 1 of 1
ennine
521 Views, 0 Replies

Import ShapeFile into Autocad Map

Hi,

I am struggling to import Shp file into Autocad Map, but I do not succeed.

I join hereafter net code, which refers mainly to the following link : here 

I have used both Autocad Map 2017 & 2020. I think I am missing something.

Any help is welcome.

 

namespace ImportShp
{
    public class ImportShpUtils
    {
        [CommandMethod ("ISHP")]
        public void ImportLayer()
        {
            ImportShpForm layerForm = new ImportShpForm();
            layerForm.Show();
        }
        public void ImportShpProcess(FileInfo shpfileInfo)
        {
            Stopwatch sw = new Stopwatch();
            sw.Start();
            MapApplication mapApp = HostMapApplicationServices.Application;
            using (Importer importer = mapApp.Importer)
            {
                importer.Init("SHP", shpfileInfo.FullName);

                string fileName = Path.GetFileNameWithoutExtension(shpfileInfo.FullName).Replace(" ", "");
                foreach (InputLayer inLayer in importer)
                {
                    inLayer.SetLayerName(LayerNameType.LayerNameDirect, fileName);
                    inLayer.SetDataMapping(ImportDataMapping.NewObjectDataOnly, fileName);
                    inLayer.Dispose();
                }
                importer.ImportPolygonsAsClosedPolylines = true;
                ImportResults result = importer.Import(true);
                sw.Stop();
                importer.Dispose();
            }
            shpfileInfo.Delete();
        }
    }
}
Labels (3)
0 REPLIES 0

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Technology Administrators


AutoCAD Beta