.NET
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Problem to import Shapefile in C3D with DialogBox

2 REPLIES 2
SOLVED
Reply
Message 1 of 3
m.chavet7MJRB
158 Views, 2 Replies

Problem to import Shapefile in C3D with DialogBox

I'm trying to import a shapefile into C3D with a C# code. I get this error when I run the function:

 

 

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

************** Exception Text **************
System.ArgumentException: Cannot bind to the target method because its signature or security transparency is not compatible with that of the delegate type.
at System.Delegate.CreateDelegate(Type type, Object firstArgument, MethodInfo method, Boolean throwOnBindFailure)
at System.Delegate.CreateDelegate(Type type, Object firstArgument, MethodInfo method)
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.CommandClass.CommandThunk.Invoke()

 

 

 

The code : 

 

 

[CommandMethod("AEPImportShape")]
static public string ImportShape()
{


    Stopwatch sw = new Stopwatch();
    sw.Start();
    MapApplication mapApp = HostMapApplicationServices.Application;
    Importer importer = mapApp.Importer;
    //using (Importer importer = mapApp.Importer)
    //{

        //static string[] SelectDwgFiles()
        //{
        // Create an instance of the OpenFileDialog class.    
        Autodesk.AutoCAD.Windows.OpenFileDialog ofd = new Autodesk.AutoCAD.Windows.OpenFileDialog("Select Shapefile", null, 
            "shp", "Select shp", Autodesk.AutoCAD.Windows.OpenFileDialog.OpenFileDialogFlags.AllowAnyExtension);
        // Show common dialog box and determine if DialogResult = OK.    
        if (ofd.ShowDialog() == System.Windows.Forms.DialogResult.OK)
        {
            string shpFiles = ofd.GetFilenames()[0];
            //Array.Sort(shpFiles);
           
            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);
                //importer.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();

            dynamic acadApp = Autodesk.AutoCAD.ApplicationServices.Application.AcadApplication;
            acadApp.ZoomExtents();

            return shpFiles;

        }
        else
            return null;
        //}

    //}

    //_shpname.Delete();
}
#endregion

 

 

2 REPLIES 2
Message 2 of 3
norman.yuan
in reply to: m.chavet7MJRB

From your previous posts, it seems you have had done importing shape file successfully. With your this post, it seems you emphasize with "... DialogBox", which should have nothing to do with the importing itself. So, my question is have you done your due debugging at all, stepping through the code to locate which line of code causes the exception? Say, you can hard-code a shape file name, instead of using open file dialog, to prove the importing works before you add the dialog box.

 

It is not very nice to post many line of code and only say "I got error" without providing how you tried in debugging, and let others to guess which line of code could be the source.

 

In your case, if a valid shape file name is supplied but the importing fails, you could compare it to your previous code asked in the other thread to see what the differences are. If the code is the same, then maybe the shape file is corrupted for some reasons.

 

Norman Yuan

Drive CAD With Code

EESignature

Message 3 of 3
m.chavet7MJRB
in reply to: norman.yuan

Hello Norman,

 

Thank you for your reply, you're totally right, I'm sorry.

 

I found by myself, I had to replace "static string" by "void".

 

Yes, I get how to import a shapefile with a simple line, but here I looked for how to import with a dialog box. The file was not corrupted

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

Post to forums  

Forma Design Contest


AutoCAD Beta