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();
}
}
}