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
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
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) :
So you can not pass those strings to Marshal.GetActiveObject()
Відповідь корисна? Клікніть на "ВПОДОБАЙКУ" цім повідомленням! | Do you find the posts helpful? "LIKE" these posts!
Находите сообщения полезными? Поставьте "НРАВИТСЯ" этим сообщениям!
На ваше запитання відповіли? Натисніть кнопку "ПРИЙНЯТИ РІШЕННЯ" | Have your question been answered successfully? Click "ACCEPT SOLUTION" button.
На ваш вопрос успешно ответили? Нажмите кнопку "УТВЕРДИТЬ РЕШЕНИЕ"
Alexander Rivilis / Александр Ривилис / Олександр Рівіліс
Programmer & Teacher & Helper / Программист - Учитель - Помощник / Програміст - вчитель - помічник
Facebook | Twitter | LinkedIn
![]() | ![]() |
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.
@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.
Відповідь корисна? Клікніть на "ВПОДОБАЙКУ" цім повідомленням! | Do you find the posts helpful? "LIKE" these posts!
Находите сообщения полезными? Поставьте "НРАВИТСЯ" этим сообщениям!
На ваше запитання відповіли? Натисніть кнопку "ПРИЙНЯТИ РІШЕННЯ" | Have your question been answered successfully? Click "ACCEPT SOLUTION" button.
На ваш вопрос успешно ответили? Нажмите кнопку "УТВЕРДИТЬ РЕШЕНИЕ"
Alexander Rivilis / Александр Ривилис / Олександр Рівіліс
Programmer & Teacher & Helper / Программист - Учитель - Помощник / Програміст - вчитель - помічник
Facebook | Twitter | LinkedIn
![]() | ![]() |
Can't find what you're looking for? Ask the community or share your knowledge.