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: 

Recurring problem when importing shapefile in C3D with Objects Data

4 REPLIES 4
SOLVED
Reply
Message 1 of 5
m.chavet7MJRB
983 Views, 4 Replies

Recurring problem when importing shapefile in C3D with Objects Data

m.chavet7MJRB
Enthusiast
Enthusiast

Hello,

I'm currently importing shapefiles via C# code into Civil3D with its attributes converted into FDO.

After a few imports, it happens that the file becomes "corrupted", i.e. I'm no longer authorized to import it with Objects Data.

If I remove the line that allows the attributes to be imported, the import works (like a normal Mapimport). The line of code is: "inputLayer.SetDataMapping(ImportDataMapping.NewObjectDataOnly, fileName);"

 

Here is my code :

 

 

 

 

 

 

[CommandMethod("AEPImportShape")]

public void AEPImportShape()
{
    Stopwatch sw = new Stopwatch();
    sw.Start();
    MapApplication mapApp = HostMapApplicationServices.Application;
    using (Importer importer = mapApp.Importer)
    {
      
        Autodesk.AutoCAD.Windows.OpenFileDialog ofd = new Autodesk.AutoCAD.Windows.OpenFileDialog("Select Shapefile", null, 
            "shp", "Select shp", Autodesk.AutoCAD.Windows.OpenFileDialog.OpenFileDialogFlags.AllowAnyExtension);
     
        if (ofd.ShowDialog() == System.Windows.Forms.DialogResult.OK)
        {

            //Array.Sort(shpFiles);
            string shpFiles = ofd.GetFilenames()[0];
            importer.Init("SHP", shpFiles);

            string fileName = Path.GetFileNameWithoutExtension(shpFiles).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();
            
            //importer.Dispose();
            dynamic acadApp = Autodesk.AutoCAD.ApplicationServices.Application.AcadApplication;
            acadApp.ZoomExtents();
        }
        
    }

}

 

 

 

 

 

If I copy the shapefile, and retry the import, sometimes it works with the ODs. I repeated this manip several times. 

 

Here is the error:

Application does not support just-in-time (JIT)
debugging. See the end of this message for details.

************** Exception Text **************
Autodesk.Gis.Map.MapImportExportException: Exception of type 'Autodesk.Gis.Map.MapImportExportException' was thrown.
at Autodesk.Gis.Map.ImportExport.Importer.Init(String formatName, String fileName)
at AEPCreateProfile.MyCommandsAEP.AEPImportShape() in C:\Users\maxime.chavet\Documents\RDC29\VISUAL_STUDIO\Profile\Profile\Class1.cs:line 68
at Autodesk.AutoCAD.Runtime.CommandClass.InvokeWorker(MethodInfo mi, Object commandObject, Boolean bLispFunction)
at Autodesk.AutoCAD.Runtime.CommandClass.InvokeWorkerWithExceptionFilter(MethodInfo mi, Object commandObject, Boolean bLispFunction)
at Autodesk.AutoCAD.Runtime.PerDocumentCommandClass.Invoke(MethodInfo mi, Boolean bLispFunction)
at Autodesk.AutoCAD.Runtime.CommandClass.CommandThunk.Invoke()

0 Likes

Recurring problem when importing shapefile in C3D with Objects Data

Hello,

I'm currently importing shapefiles via C# code into Civil3D with its attributes converted into FDO.

After a few imports, it happens that the file becomes "corrupted", i.e. I'm no longer authorized to import it with Objects Data.

If I remove the line that allows the attributes to be imported, the import works (like a normal Mapimport). The line of code is: "inputLayer.SetDataMapping(ImportDataMapping.NewObjectDataOnly, fileName);"

 

Here is my code :

 

 

 

 

 

 

[CommandMethod("AEPImportShape")]

public void AEPImportShape()
{
    Stopwatch sw = new Stopwatch();
    sw.Start();
    MapApplication mapApp = HostMapApplicationServices.Application;
    using (Importer importer = mapApp.Importer)
    {
      
        Autodesk.AutoCAD.Windows.OpenFileDialog ofd = new Autodesk.AutoCAD.Windows.OpenFileDialog("Select Shapefile", null, 
            "shp", "Select shp", Autodesk.AutoCAD.Windows.OpenFileDialog.OpenFileDialogFlags.AllowAnyExtension);
     
        if (ofd.ShowDialog() == System.Windows.Forms.DialogResult.OK)
        {

            //Array.Sort(shpFiles);
            string shpFiles = ofd.GetFilenames()[0];
            importer.Init("SHP", shpFiles);

            string fileName = Path.GetFileNameWithoutExtension(shpFiles).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();
            
            //importer.Dispose();
            dynamic acadApp = Autodesk.AutoCAD.ApplicationServices.Application.AcadApplication;
            acadApp.ZoomExtents();
        }
        
    }

}

 

 

 

 

 

If I copy the shapefile, and retry the import, sometimes it works with the ODs. I repeated this manip several times. 

 

Here is the error:

Application does not support just-in-time (JIT)
debugging. See the end of this message for details.

************** Exception Text **************
Autodesk.Gis.Map.MapImportExportException: Exception of type 'Autodesk.Gis.Map.MapImportExportException' was thrown.
at Autodesk.Gis.Map.ImportExport.Importer.Init(String formatName, String fileName)
at AEPCreateProfile.MyCommandsAEP.AEPImportShape() in C:\Users\maxime.chavet\Documents\RDC29\VISUAL_STUDIO\Profile\Profile\Class1.cs:line 68
at Autodesk.AutoCAD.Runtime.CommandClass.InvokeWorker(MethodInfo mi, Object commandObject, Boolean bLispFunction)
at Autodesk.AutoCAD.Runtime.CommandClass.InvokeWorkerWithExceptionFilter(MethodInfo mi, Object commandObject, Boolean bLispFunction)
at Autodesk.AutoCAD.Runtime.PerDocumentCommandClass.Invoke(MethodInfo mi, Boolean bLispFunction)
at Autodesk.AutoCAD.Runtime.CommandClass.CommandThunk.Invoke()

4 REPLIES 4
Message 2 of 5
fieldguy
in reply to: m.chavet7MJRB

fieldguy
Advisor
Advisor

your code works ok for me, but i don't have much shp data to test. do you have a problem file you can share?

 

the error msg you posted indicates an error occurred at line 68 in Class1.cs - that does not match the code you posted.

have you tried a try{} catch{} structure to check for MapException?  

0 Likes

your code works ok for me, but i don't have much shp data to test. do you have a problem file you can share?

 

the error msg you posted indicates an error occurred at line 68 in Class1.cs - that does not match the code you posted.

have you tried a try{} catch{} structure to check for MapException?  

Message 3 of 5
m.chavet7MJRB
in reply to: fieldguy

m.chavet7MJRB
Enthusiast
Enthusiast

Thank you for your answer

 

As I said, it's this line: inputLayer.SetDataMapping(ImportDataMapping.NewObjectDataOnly, fileName);  ; when I import the Object Data.

 

I tried a lot of things to repair these data in QGIS but it still doesn't work. I generated again the entire layer, but it doesn't work. I tried with another point layer and it works.

 

You can download the data here: https://we.tl/t-KMt8pFRZuV

0 Likes

Thank you for your answer

 

As I said, it's this line: inputLayer.SetDataMapping(ImportDataMapping.NewObjectDataOnly, fileName);  ; when I import the Object Data.

 

I tried a lot of things to repair these data in QGIS but it still doesn't work. I generated again the entire layer, but it doesn't work. I tried with another point layer and it works.

 

You can download the data here: https://we.tl/t-KMt8pFRZuV

Message 4 of 5
m.chavet7MJRB
in reply to: fieldguy

m.chavet7MJRB
Enthusiast
Enthusiast

I got this Exception Thrown :

 

System.NullReferenceException: 'Object reference not set to an instance of an object.'

0 Likes

I got this Exception Thrown :

 

System.NullReferenceException: 'Object reference not set to an instance of an object.'

Message 5 of 5
fieldguy
in reply to: m.chavet7MJRB

fieldguy
Advisor
Advisor
Accepted solution

the problem is the length of "fname" - it's ok to create a layer name but too long for a table name.

SetLayerName(LayerNameType.LayerNameDirect, fname) // works
SetDataMapping(ImportDataMapping.NewObjectDataOnly, fname) // does not work

 

if you use OOTB "MapImport", you will see that autocad truncates the table name to 25 chars.  QGIS does not.

 

 

the problem is the length of "fname" - it's ok to create a layer name but too long for a table name.

SetLayerName(LayerNameType.LayerNameDirect, fname) // works
SetDataMapping(ImportDataMapping.NewObjectDataOnly, fname) // does not work

 

if you use OOTB "MapImport", you will see that autocad truncates the table name to 25 chars.  QGIS does not.

 

 

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report