Author Topic: Map .net Locks Shape File after Import  (Read 217 times)

0 Members and 1 Guest are viewing this topic.

FriendFromArea51

  • Swamp Rat
  • Posts: 707
  • Mars sucks!
Map .net Locks Shape File after Import
« 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.  

n.yuan

  • Bull Frog
  • Posts: 240
Re: Map .net Locks Shape File after Import
« Reply #1 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.

FriendFromArea51

  • Swamp Rat
  • Posts: 707
  • Mars sucks!
Re: Map .net Locks Shape File after Import
« Reply #2 on: October 18, 2017, 11:51:45 am »
Bummer. Thank you n.yuan

huiz

  • Swamp Rat
  • Posts: 782
  • Certified Prof C3D
Re: Map .net Locks Shape File after Import
« Reply #3 on: October 19, 2017, 03:22:52 am »
You can copy the file to a temp-location and use that instead of the original.
The conclusion is justified that the initialization of the development of critical subsystem optimizes the probability of success to the development of the technical behavior over a given period.

FriendFromArea51

  • Swamp Rat
  • Posts: 707
  • Mars sucks!
Re: Map .net Locks Shape File after Import
« Reply #4 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

kdub

  • SuperMod
  • Swamp Rat
  • Posts: 993
  • class keyThumper<T>:ILazy<T>
Re: Map .net Locks Shape File after Import
« Reply #5 on: October 19, 2017, 11:16:51 pm »

On the chance of future action can you report this to AutoDesk.
called Kerry in my other life

Sometimes the question is more important than the answer.

FriendFromArea51

  • Swamp Rat
  • Posts: 707
  • Mars sucks!
Re: Map .net Locks Shape File after Import
« Reply #6 on: October 20, 2017, 12:04:49 am »
Definitely.