snippets : Launch Autocad from a .NET application

.NET : Launch Autocad from a .NET applicationThis code in C# .NET launch AutoCAD from an application, and handle the process to interact with it.
public static void Launch_Autocad()
        {
            // "AutoCAD.Application.16.2" uses 2006
            // "AutoCAD.Application.17" uses 2007 or 2008, whichever was most recently run
            // "AutoCAD.Application.17.1" uses 2008, specifically
            // "AutoCAD.Application.18" uses 2010

            const string progID = "AutoCAD.Application.17.1";

            AcadApplication acApp = null;
            try
            {
                acApp = (AcadApplication)Marshal.GetActiveObject(progID);
            }
            catch
            {
                try
                {
                    Type acType = Type.GetTypeFromProgID(progID);
                    acApp = (AcadApplication)Activator.CreateInstance(acType, true);
                }
                catch
                {
                    MessageBox.Show("Cannot create object of type \"" +progID + "\"");
                }
            }
            if (acApp != null)
            {
                try
                {
                    // By the time this is reached AutoCAD is fully
                    // functional and can be interacted with through code
                    acApp.Visible = true;

                   //Here you can call AutoCAD functions or interact with a dll based on OBJECTARX and COM registered

                }
                catch (System.Exception ex)
                {
                    MessageBox.Show("Problem executing component: " + ex.Message);
                }
            }
        }
tags : .NET

all tags : python, system, vlc, video, apache, proxy, linux, django, MySQL, .NET, XML, XSL, regexp, bat, windows, bash, git

back to snippets home
site réalisé et hébergé par revolunet © 2009 - informations légales