.NET

Reply
Distinguished Contributor
alex_b
Posts: 405
Registered: ‎08-15-2003
Message 1 of 6 (473 Views)

Acad version - interop problem

473 Views, 5 Replies
02-16-2013 03:21 AM

Hi

Please consider the following code:

public static object openAutoCAD(string AcadVersion)
{
object acadApp = null;
object[] parameters;
object cmd = null;
string progID = "AutoCAD.Application." + AcadVersion;
// try to open an existing instance
try
{
acadApp = (object)Marshal.GetActiveObject(progID);//exception
}
catch // if not successful try to start a new instance
...............

 The above code works fine when the function parameter is 17.1 (V2008) or 18.2 (V2012).

It fails with "co_e_classstring exception" when passed 16.0 (V2004).

The program is compiled with VS 2008/NET 3.5.

The passed Acad version is of course up and running prior to the function call.

The Acad version should make no differrence and yet we get an exception on V2004.

 

Any explanation/help will be greatly appreciated.

 

Thanks

 

alex

*Expert Elite*
_gile
Posts: 2,133
Registered: ‎04-29-2006
Message 2 of 6 (469 Views)

Re : Acad version - interop problem

02-16-2013 03:44 AM in reply to: alex_b

Hi,

 

It seems to me the first AutoCAD version supporting .NET is 2005 (or 2006).

Gilles Chanteau
Distinguished Contributor
alex_b
Posts: 405
Registered: ‎08-15-2003
Message 3 of 6 (449 Views)

Re : Acad version - interop problem

02-16-2013 06:39 AM in reply to: _gile

Gilles:

 

Thank you for your answer.

 

You are right, it is 2005, but in the meantime I discovered something: if I call the function passing as parameter "16", which is the major version of  V2004, V2005 and V2006 instead of "16.0" for the actual installed version (V2004), the function works OK (it connects to a running instance of Acad 2004 or launches a new one).

I would very much like to understand why is it so.

 

alex

Moderator
Alexander.Rivilis
Posts: 1,457
Registered: ‎04-09-2008
Message 4 of 6 (437 Views)

Re : Acad version - interop problem

02-16-2013 10:18 AM in reply to: alex_b

There is no key AutoCAD.Application.16.0 in registry (as far as AutoCAD.Application.17.0, AutoCAD.Application.18.0, AutoCAD.Application.19.0) :

 

16-02-2013 20-03-16.png

 

So you can not pass those strings to Marshal.GetActiveObject()


Пожалуйста не забывайте про Утвердить в качестве решения! Утвердить в качестве решения и Give Kudos!Баллы
Please remember to Accept Solution! Accept as Solution and Give Kudos!Kudos

Distinguished Contributor
alex_b
Posts: 405
Registered: ‎08-15-2003
Message 5 of 6 (425 Views)

Re : Acad version - interop problem

02-16-2013 12:27 PM in reply to: Alexander.Rivilis

Unless I'm missing something, yes there is.

Try this to list all Acads installed on your system:

RegistryKey root = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Autodesk\AutoCAD");
result = root.GetSubKeyNames();

 If you have V2004, one of the keys you get is 16.0 (at least on my machine).

Maybe the AutoCAD.Application keys do not map one-to-one to the installed versions. If so, is there a mapping and an explanation?

Thank you.

Moderator
Alexander.Rivilis
Posts: 1,457
Registered: ‎04-09-2008
Message 6 of 6 (420 Views)

Re : Acad version - interop problem

02-16-2013 02:02 PM in reply to: alex_b

alex_b wrote:

...Maybe the AutoCAD.Application keys do not map one-to-one to the installed versions...


Yes. Moreover I have not installed AutoCAD 2004 and AutoCAD 2005. I have only AutoCAD 2006 from R16 line, but as you see in my registry under HKEY_CLASSES_ROOT key I have AutoCAD.Application.16, AutoCAD.Application.16.1, AutoCAD.Application.16.2 subkeys. And all of them refer to AutoCAD 2006. So there is no direct mapping between installed version and it's AutoCAD.Application.XX.X keys.


Пожалуйста не забывайте про Утвердить в качестве решения! Утвердить в качестве решения и Give Kudos!Баллы
Please remember to Accept Solution! Accept as Solution and Give Kudos!Kudos

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.