.NET

Reply
Contributor
cvaught
Posts: 18
Registered: ‎01-25-2012
Message 1 of 14 (822 Views)

Connecting to AutoCAD

822 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.

Distinguished Contributor
mohnston
Posts: 184
Registered: ‎09-22-2006
Message 2 of 14 (779 Views)

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
Contributor
cvaught
Posts: 18
Registered: ‎01-25-2012
Message 3 of 14 (769 Views)

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);

}

}

ADN Support Specialist
Balaji_Ram
Posts: 749
Registered: ‎03-21-2011
Message 4 of 14 (755 Views)

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

Contributor
cvaught
Posts: 18
Registered: ‎01-25-2012
Message 5 of 14 (745 Views)

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.

ADN Support Specialist
Balaji_Ram
Posts: 749
Registered: ‎03-21-2011
Message 6 of 14 (739 Views)

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

Contributor
cvaught
Posts: 18
Registered: ‎01-25-2012
Message 7 of 14 (688 Views)

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?

Contributor
cvaught
Posts: 18
Registered: ‎01-25-2012
Message 8 of 14 (627 Views)

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.

*Expert Elite*
Hallex
Posts: 1,569
Registered: ‎10-08-2008
Message 9 of 14 (604 Views)

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
Contributor
cvaught
Posts: 18
Registered: ‎01-25-2012
Message 10 of 14 (545 Views)

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?

Post to the Community

Have questions about Autodesk products? Ask the community.

New Post
Announcements
Do you have 60 seconds to spare? The Autodesk Community Team is revamping our site ranking system and we want your feedback! Please click here to launch the 5 question survey. As always your input is greatly appreciated.