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()
Solved! Go to Solution.
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()
Solved! Go to Solution.
Solved by fieldguy. Go to Solution.
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?
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?
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
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
I got this Exception Thrown :
System.NullReferenceException: 'Object reference not set to an instance of an object.'
I got this Exception Thrown :
System.NullReferenceException: 'Object reference not set to an instance of an object.'
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.