AutoCAD Map 3D Developer
Welcome to Autodesk’s AutoCAD Map 3D Developer Forums. Share your knowledge, ask questions, and explore popular AutoCAD Map 3D Developer topics.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

SHP Import Locking .shp file

4 REPLIES 4
SOLVED
Reply
Message 1 of 5
mordend
774 Views, 4 Replies

SHP Import Locking .shp file

mordend
Enthusiast
Enthusiast

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();
        }
0 Likes

SHP Import Locking .shp file

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();
        }
4 REPLIES 4
Message 2 of 5
Alfred.NESWADBA
in reply to: mordend

Alfred.NESWADBA
Consultant
Consultant

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 -

------------------------------------------------------------------------------------
Alfred NESWADBA
ISH-Solutions GmbH / Ingenieur Studio HOLLAUS
www.ish-solutions.at ... blog.ish-solutions.at ... LinkedIn ... CDay 2024
------------------------------------------------------------------------------------

(not an Autodesk consultant)
0 Likes

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 -

------------------------------------------------------------------------------------
Alfred NESWADBA
ISH-Solutions GmbH / Ingenieur Studio HOLLAUS
www.ish-solutions.at ... blog.ish-solutions.at ... LinkedIn ... CDay 2024
------------------------------------------------------------------------------------

(not an Autodesk consultant)
Message 3 of 5
norman.yuan
in reply to: mordend

norman.yuan
Mentor
Mentor
Accepted solution

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.

Norman Yuan

Drive CAD With Code

EESignature

0 Likes

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.

Norman Yuan

Drive CAD With Code

EESignature

Message 4 of 5
mordend
in reply to: Alfred.NESWADBA

mordend
Enthusiast
Enthusiast

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.

0 Likes

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.

Message 5 of 5
mordend
in reply to: norman.yuan

mordend
Enthusiast
Enthusiast
Accepted solution

So testing in 2017 it is still an issue.

 

But good news is that it seems to be fixed in 2020. YAY!!!

 

Thanks Norman.

0 Likes

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.

Post to forums  

Autodesk Design & Make Report