C# and ModelSpace Error

Discussion in 'AutoCAD' started by TCoyle, Sep 2, 2004.

  1. TCoyle

    TCoyle Guest

    I am upgrading a C# program to use AutoCAD 2000 Mechanical instead of AutoCAD 2000. When I attempt to retrieve a reference to Model Space (see code below), I get the following error:

    An unhandled exception of type 'System.Runtime.InteropServices.COMException' occurred in TestAutoCAD2004.exe

    Additional information: Error loading type library/DLL.

    Not sure what is going on. Any ideas?

    <code snippet>
    AutoCAD.AcadApplication oApp;
    AutoCAD.AcadDocument oDoc;
    AutoCAD.AcadModelSpace oMSpace;


    oApp = (AutoCAD.AcadApplication)System.Runtime.InteropServices.Marshal.GetActiveObject("AutoCAD.Application");
    oDoc = oApp.Documents.Add(null);
    oMSpace = oDoc.ModelSpace;
     
    TCoyle, Sep 2, 2004
    #1
  2. For starters you'll need to reference the Mechnical libraries in additon to
    the AutoCAD libraries. Without looking further into it, that might be part
    of your problem. The other problem is that you need to set your document to
    the active document.

    -- Mike
    ___________________________
    Mike Tuersley
    CADalyst's CAD Clinic
    Rand IMAGINiT Technologies
    ___________________________
    the trick is to realize that there is no spoon...
     
    Mike Tuersley, Sep 2, 2004
    #2
  3. Oops - I re-read and see you are using 2004 or 2000(?) - either way you
    have to write your own com interop - that'll be a pain for all the mech
    libs

    -- Mike
    ___________________________
    Mike Tuersley
    CADalyst's CAD Clinic
    Rand IMAGINiT Technologies
    ___________________________
    the trick is to realize that there is no spoon...
     
    Mike Tuersley, Sep 2, 2004
    #3
  4. TCoyle

    TCoyle Guest

    Thanks Mike. I had to reference the 4 mechanical lib's in order to get this to work. I used VS.NET to write the COM wrappers for me. Thanks again.
     
    TCoyle, Sep 3, 2004
    #4
  5. TCoyle

    danrald Guest

    Does anyone know of some good docs on intergration of C# and AutoCAD???
    Thanks
     
    danrald, Sep 3, 2004
    #5
Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.