Code Red > .NET

Map .net Locks Shape File after Import

(1/2) > >>

nobody:
Map appears to keep a connection to the shape file after importing it the way I show below. Anyone know how I can disconnect it?


--- Code - C#: ---Autodesk.Gis.Map.ImportExport.Importer myimporter = null;Autodesk.Gis.Map.MapApplication mapapp = Autodesk.Gis.Map.HostMapApplicationServices.Application;myimporter = mapapp.Importer;  myimporter.Init("SHP", file);myimporter.ImportPolygonsAsClosedPolylines = true;                        myimporter.Import(true);                       

n.yuan:
This is a known issue since the first release of AutoCAD Map .NET API and I could imagine it has been reported to Autodesk many years ago and never been dealt with.

Since manaully executing "MapImport" command does not lock the shape file. I guess it is a flaw of implementing Autodesk.Gis.Map.ImportExport.Import class in AutoCAD Map .NET API that results in the locking.

Because Importer class is IDisposable, we could try to Dispose() it after the importing is done:

            var mapApp = HostMapApplicationServices.Application;
            using (var importer = mapApp.Importer)
            {
                importer.Init("SHP", shpFile);
                importer.Import(true);
            }

Although, theoretically, we should not have to dispose it, because it is a property of MapApplication, not created by our code (again, we do not know how the property is implemented, the property's "get" accessor may actually create an instance of some class, who knows).

But, disposing does not release the lock. The only way to unlock the shape file is to end the AutoCAD session, it seems.

nobody:
Bummer. Thank you n.yuan

huiz:
You can copy the file to a temp-location and use that instead of the original.

nobody:
Yea, that's what I ended up doing. Using date/time to give it a unique name but that just meant those ones were locked XD.. not sure how to go about cleaning it up. Maybe a script during log in or something idk

Navigation

[0] Message Index

[#] Next page

Go to full version