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

0 Members and 1 Guest are viewing this topic.

nobody

  • Swamp Rat
  • Posts: 861
  • .net stuff
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: 348
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.

nobody

  • Swamp Rat
  • Posts: 861
  • .net stuff
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: 913
  • 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.

nobody

  • Swamp Rat
  • Posts: 861
  • .net stuff
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_nz

  • Mesozoic keyThumper
  • SuperMod
  • Water Moccasin
  • Posts: 2121
  • 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
Retired; but they dragged me back in !

I live at UTC + 13.00

---
some people complain about loading the dishwasher.
Sometimes the question is more important than the answer.

nobody

  • Swamp Rat
  • Posts: 861
  • .net stuff
Re: Map .net Locks Shape File after Import
« Reply #6 on: October 20, 2017, 12:04:49 AM »
Definitely.