• Industries
  • Products
  • Buy
  • Services & Support
  • Communities
  • Discussion Groups

    .NET

    Reply
    Contributor
    cvaught
    Posts: 11
    Registered: ‎01-25-2012

    Connecting to AutoCAD

    630 Views, 13 Replies
    01-25-2012 05:24 PM

    I have a .NET app that I have created to run inside of AutoCAD.  It runs inside of AutoCAD and has been tested on both AutoCAD 2010 and 2012.  I have also built a standalone applicaiton that is intended to start AutoCAD and netload the in process dll.  I have a computer that has 2010 installed and if I compile the application on this machine everything works as it should.  If I then run the same standalone application on a computer that only has 2012 installed it doesn't connect.  It starts AutoCAD (acad.exe shows up in the task manager) but it can't connect to it.  I then tested the opposite scenario.  Built the standalone application on a computer that only has 2012 installed and it works with AutoCAD 2012.  I then ran that applicaiton on the computer with only AutoCAD 2010 installed and it can't connect.  Just like before, acad.exe is started but it doesn't connect and instead gives an error.

     

    Obviously this would make supporting different versions of AutoCAD require a different executables for the standalone application which seems wrong.  I have created a applicaiton that communicates with Inventor and this problem did not occur.  Thus, I had assumed it wouldn't be an issue with AutoCAD.   Am I doing something wrong that is preventing the different versions from working?   Any help would be greatly appreciated.

    Please use plain text.
    Distinguished Contributor
    Posts: 181
    Registered: ‎09-22-2006

    Re: Connecting to AutoCAD

    01-26-2012 02:49 PM in reply to: cvaught

    If you post the code from the stand-alone app that starts AutoCAD then netloads the in-process dll you might get a better response.

    CAD Programming Solutions
    Please use plain text.
    Contributor
    cvaught
    Posts: 11
    Registered: ‎01-25-2012

    Re: Connecting to AutoCAD

    01-26-2012 04:29 PM in reply to: cvaught

    Here is the code for connecting to AutoCAD.

     

    public void connectAutoCad()

    {

    String progID = "Application.AutoCAD";

    try

            {

                   //try to connect an open instance of autoCad

                   acApp = (AcadApplication)Marshal.GetActiveObject(progID);

            }

            catch

            {

            //open a new instance autoCad

                    Type acType = Type.GetTypeFromProgID(progID);

                    acApp =(AcadApplication)Activator.CreateInstance(acType,true);

    }

    }

    Please use plain text.
    ADN Support Specialist
    Balaji_Ram
    Posts: 384
    Registered: ‎03-21-2011

    Re: Connecting to AutoCAD

    01-27-2012 02:40 AM in reply to: cvaught

    Hi cvaught,

     

    Have you tried setting the visibility using "acApp.Visible = true" after "CreateInstance" call ?

    Does AutoCAD then show up ?

     

     



    Balaji
    Developer Technical Services
    Autodesk Developer Network

    Please use plain text.
    Contributor
    cvaught
    Posts: 11
    Registered: ‎01-25-2012

    Re: Connecting to AutoCAD

    01-27-2012 06:08 AM in reply to: Balaji_Ram

    It throws an exception on that line.  Thus acApp is null.

    Please use plain text.
    ADN Support Specialist
    Balaji_Ram
    Posts: 384
    Registered: ‎03-21-2011

    Re: Connecting to AutoCAD

    01-27-2012 06:34 AM in reply to: cvaught

    Hi,

     

    I have 2011 and 2012 installed and it works ok when i launch 2012.

     

    Here are few things that you may try :

     

    1) Check the following in the registry - HKEY_CLASSES_ROOT\AutoCAD.Application

        Use the CLSID mentioned to search and this should lead you to the acad.exe path that is supposed to get launched. Make sure you do this carefully and dont change anything by mistake.

     

    2) Try invoking a specific version by providing a different progId such as "AutoCAD.Application.18" and "AutoCAD.Application.18.2".

     

    3) See if the issue is specific to a system by trying it on other systems that only have 2012.

     

     



    Balaji
    Developer Technical Services
    Autodesk Developer Network

    Please use plain text.
    Contributor
    cvaught
    Posts: 11
    Registered: ‎01-25-2012

    Re: Connecting to AutoCAD

    01-30-2012 05:18 PM in reply to: Balaji_Ram

    So just to confirm, a single excutable that is created on a computer using AutoCAD 2012 should be able to connect to AutoCAD when the application is installed on a computer that only contains AutoCAD 2010?

    Please use plain text.
    Contributor
    cvaught
    Posts: 11
    Registered: ‎01-25-2012

    Re: Connecting to AutoCAD

    02-23-2012 02:10 PM in reply to: cvaught

    I still haven't found a solution for my problem.  Does anyone have experience with connecting to multiple different versions of AutoCAD with a single executable?  Any help would be greatly appreciated.

    Please use plain text.
    *Expert Elite*
    Hallex
    Posts: 1,371
    Registered: ‎10-08-2008

    Re: Connecting to AutoCAD

    02-24-2012 01:08 AM in reply to: cvaught

    Try to get the current version something like this

    {code}

            Dim acadver As Object
            acadver = My.Computer.Registry.GetValue("HKEY_CLASSES_ROOT\AutoCAD.Application\CurVer", _
                                                  String.Empty, String.Empty)

            If typeOf acadver Is String Then
                MessageBox.Show("String acadver: " & acadver.ToString
    end if

    {code}

     

    Then pull this string to CreateInstance method from

    System.Reflection namespace

     

    ~'J'~

    _____________________________________
    C6309D9E0751D165D0934D0621DFF27919
    Please use plain text.
    Contributor
    cvaught
    Posts: 11
    Registered: ‎01-25-2012

    Re: Connecting to AutoCAD

    03-03-2012 01:47 PM in reply to: Hallex

    Same problem still exists.  It starts acad.exe but cannot connect to it.  Any other opitons?  This seems like it should be pretty straight forward.  How else can a stand along application support multiple versions of AutoCAD?

    Please use plain text.