3

I have a question about integrating AutoCad LT with a WPF C# application. I have a client for whom I develop a ERP application, this client uses AutoCAD LT to draw their products which they produce. They use main-drawings for their products, different customers order this products whith different sizes.

The client asked me if it's possible to integrate and automate AutoCad with his order process. When he makes a new order he wants it to open the drawing of the product which is ordered, alter it, and save it under a different name in a particular folder.

The altering of the drawing will be done by the customer representive (CSR), the application should automatically save the drawing in a particular folder with a name which references the particular order. After that the application should print the drawing and then close the AutoCad instance.

So I have the following use case:

  1. CSR: Enter new order and specify main drawing;
  2. Application: Open AutoCad drawing;
  3. CSR: Alter drawing;
  4. CSR: Submit order (in the application);
  5. Application: Instruct AutoCad to print the altered drawing;
  6. Application: Save drawing under new name in a particular folder;
  7. Application: Close AutoCad LT instance.

My question is, is there a API for AutoCad which I can use to implement this functionality, or are there other ways to communicate these commands to AutoCad?

Makoto
  • 104,088
  • 27
  • 192
  • 230
Marcel
  • 31
  • 1
  • 3

2 Answers2

1

Look at this: AutoCad .Net Developers Guide

This introduction describes the concepts of exposing AutoCAD® objects through a managed .NET application programming interface (API).

As a side note: Why do you use folders for the drawings? A database of some sort would be better I think.

GrahamMc
  • 3,034
  • 2
  • 24
  • 29
Christian Sauer
  • 10,351
  • 10
  • 53
  • 85
  • I usually find it best to just store a link to a file/folder in the database, not the actual binary - but agree a DB of some kind will be very useful in this kind of scenario – GrahamMc Apr 25 '13 at 08:20
  • @Christian, I checked the link you send and have read about this on other sites. But as I understand this can only be used when your application is run inside autocad (as a host). I cant use it in a stand-alone application. I also read about RealDWG but the license for this is to expensive for my client, hope there are cheaper solutions. – Marcel Apr 25 '13 at 15:34
  • @Marcel Look into the Open Design Alliance libraries. Read the Wiki for the autoCAD tag for more info. – CAD bloke May 01 '13 at 23:22
  • @Marcel As an aside, if your client can't afford to pay <$10k for an AutoCAD RealDWG license + ADN then they probably can't afford to pay you. Just something for you to consider. – CAD bloke May 08 '13 at 04:42
0

In the AutoCAD developers guide under sections Basics of the AutoCAD .NET API -> Out-of-Process versus In-Process

When you develop a new application, it can either run in or out-of-process. The AutoCAD .NET API is designed to run in-process only, which is different from the ActiveX Automation library which can be used in or -out-of-process. In-process applications are designed to run in the same process space as the host application. In this case, a DLL assembly is loaded into AutoCAD which is the host application. Out-of-process applications do not run in the same space as the host application. These applications are often built as stand-alone executables. If you need to create a stand-alone application to drive AutoCAD, it is best to create an application that uses the CreateObject and GetObject methods to create a new instance of an AutoCAD application or return one of the instances that is currently running. Once a reference to an AcadApplication is returned, you can then load your in-process .NET application into AutoCAD by using the SendCommand method that is a member of the ActiveDocument property of the AcadApplication.

There is sample code showing how to access a running AutoCAD instance from a standalone Application. Basically you may do something like that (insert your specific progId):

[CommandMethod("ConnectToAcad")]
public static void ConnectToAcad()
{

    AcadApplication acAppComObj = null;
    const string strProgId = "AutoCAD.Application.18";

    // Get a running instance of AutoCAD
    try
    {
        acAppComObj = (AcadApplication)Marshal.GetActiveObject(strProgId);
    }
    catch // An error occurs if no instance is running
    {
        try
        {
            // Create a new instance of AutoCAD
            acAppComObj = (AcadApplication)Activator.CreateInstance(Type.GetTypeFromProgID(strProgId), true);
        }
        catch
        {
            // If an instance of AutoCAD is not created then message and exit
            System.Windows.Forms.MessageBox.Show("Instance of 'AutoCAD.Application'" +
                                                 " could not be created.");

            return;
        }
    }

    // Display the application and return the name and version
    acAppComObj.Visible = true;
    System.Windows.Forms.MessageBox.Show("Now running " + acAppComObj.Name +
                                         " version " + acAppComObj.Version);

    // Get the active document
    AcadDocument acDocComObj;
    acDocComObj = acAppComObj.ActiveDocument;

    // Optionally, load your assembly and start your command or if your assembly
    // is demandloaded, simply start the command of your in-process assembly.
    acDocComObj.SendCommand("(command " + (char)34 + "NETLOAD" + (char)34 + " " +
                            (char)34 + "c:/myapps/mycommands.dll" + (char)34 + ") ");

    acDocComObj.SendCommand("MyCommand ");
}
Markus Weber
  • 1,059
  • 1
  • 11
  • 24