TheSwamp

Code Red => .NET => Topic started by: nobody on October 18, 2017, 03:24:24 AM

Title: Map .net Locks Shape File after Import
Post by: nobody on October 18, 2017, 03:24:24 AM
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#: [Select]
  1. Autodesk.Gis.Map.ImportExport.Importer myimporter = null;
  2. Autodesk.Gis.Map.MapApplication mapapp = Autodesk.Gis.Map.HostMapApplicationServices.Application;
  3. myimporter = mapapp.Importer;
  4.  
  5.  
  6. myimporter.Init("SHP", file);
  7. myimporter.ImportPolygonsAsClosedPolylines = true;                        
  8. myimporter.Import(true);
  9.                      
  10.  
Title: Re: Map .net Locks Shape File after Import
Post by: n.yuan on October 18, 2017, 10:00:51 AM
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.
Title: Re: Map .net Locks Shape File after Import
Post by: nobody on October 18, 2017, 11:51:45 AM
Bummer. Thank you n.yuan
Title: Re: Map .net Locks Shape File after Import
Post by: huiz on October 19, 2017, 03:22:52 AM
You can copy the file to a temp-location and use that instead of the original.
Title: Re: Map .net Locks Shape File after Import
Post by: nobody on October 19, 2017, 10:02:28 PM
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
Title: Re: Map .net Locks Shape File after Import
Post by: kdub_nz on October 19, 2017, 11:16:51 PM

On the chance of future action can you report this to AutoDesk.
Title: Re: Map .net Locks Shape File after Import
Post by: nobody on October 20, 2017, 12:04:49 AM
Definitely.