Question

I'm working on this project, a .Net EXE will start AutoCAD and run some code. After googling, here is options I have:

a) Activator.CreateInstance
b) Process.Start

If I use b), it is hard to control the code after AutoCAD start. so a) is the only choice. On my client's machine, it is possible have multiple AutoCAD installed, different version (2008, 2009, 2010, 2011, etc), different favor (AutoCAD Vanilla, AutoCAD Map, AutoCAD Architecture, etc). For different version, I can add the version number, like AutoCAD.Application.17.1 for 2008. Now different favor is the only problem I need figure out. e.g. I have AutoCAD Map and AutoCAD Architecture installed on my machine. They are at different folder. Activator.CreateInstance always start the latest running one. How I can start AutoCAD Map in my exe even I just use AutoCAD Architecture.

Was it helpful?

Solution

For AutoCAD Map, I think you can use AutoCADMap.Application as program ID. For ACA, it should be AecX.AecArchBaseApplication

OTHER TIPS

You can specify the program id and its version to start a particular AutoCAD version, somthing like:

    private void addCircleToACAD_Click(object sender, EventArgs e)
    {
        AcadApplication acadApp = null;
        AcadCircle circle = null;
        AcadAcCmColor color = null;
        try
        {
            object obj = Marshal.GetActiveObject("AutoCAD.Application.18");
            if (obj != null)
            {
                acadApp = obj as AcadApplication;
                double[] cen = new double[] { 0, 0, 0 };
                circle = acadApp.ActiveDocument.Database.ModelSpace.AddCircle(cen, 10);
                color = acadApp.GetInterfaceObject("Autocad.AcCmColor.18") as AcadAcCmColor;
                color.SetRGB(50, 150, 250);
                circle.TrueColor = color;
                acadApp.ZoomExtents();
            }
            else
            {
                MessageBox.Show("AutoCAD is not open or version is not right.");
            }
        }
        catch
        {
            MessageBox.Show("AutoCAD is not open or version is not right.");
        }
        finally
        {
            if (color != null) Marshal.FinalReleaseComObject(color);
            if (circle != null) Marshal.FinalReleaseComObject(circle);
            if (acadApp != null) Marshal.FinalReleaseComObject(acadApp);
        }
    }
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top