Problem when I try to touch ObjectData twice in a row in the same C3D session with C#.Net

Problem when I try to touch ObjectData twice in a row in the same C3D session with C#.Net

m.chavet7MJRB
Enthusiast Enthusiast
362 Views
4 Replies
Message 1 of 5

Problem when I try to touch ObjectData twice in a row in the same C3D session with C#.Net

m.chavet7MJRB
Enthusiast
Enthusiast

Hello,

 

I created a post a few months ago at this location: https://forums.autodesk.com/t5/net/bug-when-successively-launching-a-function-i-ve-created/m-p/12340... , which I validated too quickly by mistake... As it happens, the problem still persists.

In the same project session, when I try again to touch ObjectData (by importing them, or if I want to reread the "records" a second time), I always get 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()

 

Here is the first code to import shapefile:

 

 

[CommandMethod("SHP2")]
static public void SHP2()
{
      Autodesk.AutoCAD.Windows.OpenFileDialog ofd = new Autodesk.AutoCAD.Windows.OpenFileDialog(
          "Select SHP File", null, "shp", "Select shp", Autodesk.AutoCAD.Windows.OpenFileDialog.OpenFileDialogFlags.AllowAnyExtension);
      if (ofd.ShowDialog() == DialogResult.OK)
      {
          string shpname = ofd.Filename;
          Import2(shpname);
      }// 
}//acad command - SHP2

private static void Import2(string shpname)
{
    string fname = Path.GetFileNameWithoutExtension(shpname).Replace(" ", "");
    MapApplication mapApp = HostMapApplicationServices.Application;
    Importer importer = mapApp.Importer;
    try
    {
        importer.Init("SHP", shpname);
        foreach (InputLayer il in importer)
        {
            il.SetLayerName(LayerNameType.LayerNameDirect, fname);
            il.SetDataMapping(ImportDataMapping.NewObjectDataOnly, fname);
        }// foreach shp layer
        importer.ImportPolygonsAsClosedPolylines = true;
        ImportResults ir = importer.Import(true);
    }
    catch { }
    finally { };
}// Import2

 

 

 

Problem is at : 

 

 

il.SetDataMapping(ImportDataMapping.NewObjectDataOnly, fname);

 

 

 

And for the second :

 

 

using(DocumentLock lk = doc.LockDocument())
{
        if (psr.Status == PromptStatus.OK)
        {
            foreach (SelectedObject so in psr.Value)
            {
                using (Records records = tables.GetObjectRecords(0, so.ObjectId, Autodesk.Gis.Map.Constants.OpenMode.OpenForWrite, false))
                {
                    
                    foreach (Record record in records)  //Error at this line

 

 

 

Error is at the last line : foreach (Record record....)

0 Likes
363 Views
4 Replies
Replies (4)
Message 2 of 5

ActivistInvestor
Mentor
Mentor

The exception is in this line:

importer.Init("SHP", shpname);
0 Likes
Message 3 of 5

m.chavet7MJRB
Enthusiast
Enthusiast

Hello,

 

Indeed sorry, but if I delete the line about the objectdata, it works. So the problem comes from there.

0 Likes
Message 4 of 5

ActivistInvestor
Mentor
Mentor

Your code contains an empty catch block. What that does is suppress

and hide exceptions. It is something that you should never do.

 

If you want to know where your code first fails, add some code to the catch block that will display the exception on the command line. 

0 Likes
Message 5 of 5

m.chavet7MJRB
Enthusiast
Enthusiast

Yes, with the debug, I can assure that the problem is from there. I try to manage with this error for a some months

0 Likes