I want to be able to delete the .shp after importing it.
Attached code works but it leaves the .shp as read only until CAD closes. Am I missing something?
private void ImportShape(FileInfo file) { Stopwatch sw = new Stopwatch(); sw.Start(); MapApplication mapApp = HostMapApplicationServices.Application; using (Importer importer = mapApp.Importer) { importer.Init("SHP", file.FullName); string fileName = Path.GetFileNameWithoutExtension(file.FullName).Replace(" ", ""); foreach (InputLayer inputLayer in importer) { inputLayer.SetLayerName(LayerNameType.LayerNameDirect, fileName); inputLayer.SetDataMapping(ImportDataMapping.NewObjectDataOnly, fileName); inputLayer.Dispose(); } importer.ImportPolygonsAsClosedPolylines = true; ImportResults result = importer.Import(true); sw.Stop(); Quest_Common.ed.WriteMessage(string.Format("\n{0} object(s) imported in {1} sec(s)", result.EntitiesImported.ToString(), sw.Elapsed.Seconds)); importer.Dispose(); } file.Delete(); }
Solved! Go to Solution.
Solved by mordend. Go to Solution.
Solved by norman.yuan. Go to Solution.
Hi,
have not tried your code, but see one issue with that:
If you use the using statement like that
using (Importer importer = mapApp.Importer) {
}
then do not call
importer.Dispose()
Because using(.....){...} includes importer.Dispose at the end of {...}
- alfred -
AFAIK, this has been a known issue for years, but I have not tried to see if it is fixed in later version after AutoCAD Map/Civil 2015.
I'm aware that the using statement calls dispose when it's closed, and that is the point of it.
I had it in there to see if it made any difference. But thank you for pointing it out.
So testing in 2017 it is still an issue.
But good news is that it seems to be fixed in 2020. YAY!!!
Thanks Norman.
Can't find what you're looking for? Ask the community or share your knowledge.