.NET

.NET

Reply
*Expert Elite*
norman.yuan
Posts: 987
Registered: ‎04-27-2009
Message 11 of 24 (745 Views)

Re: Starting AutoCAD 2012 on a W7 64bit Machine from VS 2010 Express

12-29-2011 12:07 PM in reply to: egcallis

I am not sure whether the code you showed here is in the same project you attached or not.

 

However, I opened your attached project in my VS2010 (the box has Acad2012/Win7 64bit installed) and immediately notice 2 things are not correct:

 

1. You cannot set reference to AutoCAD managed API dll (acdbmgd.dll and acmgd.dll) in your stand-alone app. TYhey can only be used in in-process DLL.

 

Your code of this line:

 

Get             Return AcadApp.DocumentManager.MdiActiveDocument.AcadDocument         End Get

 

is definitely wrong: a. AcadApp is and AcadApplication object, it does not have a property "DocumentManager"; b. DocumentManager is a Managed API class, you cannot use it in stand-alon app.

 

After removing acdbmgd.dll and acmgd.dll, VB.NET does not catch the property error of that line of code because "Option Strict" is not set on.

 

This is considered bad practice, especially when not very experinced programmer depends on VB does too much behand the scene without knowing what is really happening (that was one reason I preferred C# years ago when I moved from VB classical to .NET).

 

2. In project properties window->compile tab, click "Advanced compile options..." button, you set "Target CPU" to "x86". It is OK if the app is to run in WinXP/Vista/Win7 32-bit box. However, your target is 64-bit Acad, it can only be installed with 64-bit Windows (unless you hack the installation, this is out of this discussion). As I said in previous reply, you shoud target "Any CPU" unless you have special reason not to.

 

After some limited correction (removed acdbmgd.dll/acmgd.dll references and set target CPU to ANYCPU, I have no problem to started AutoCAD from your project. Of course I still left "Option Strict" off, or the project will not compile. And of course the program will not go further, because ThisDrawing propery is wrong as aforementioned.

 

I had to admit, I use full VS2010. But in this case, I do not see it is significant using full VS2010 or VS2010 Express.

 

 

Contributor
egcallis
Posts: 23
Registered: ‎09-14-2009
Message 12 of 24 (741 Views)

Re: Starting AutoCAD 2012 on a W7 64bit Machine from VS 2010 Express

12-29-2011 01:27 PM in reply to: norman.yuan

Yes the code I pasted was the same as from the project zip. I've brought the code into VS 2005, tunred on strict and have addressed all the issues. Remeber I said that this was coming from VBA,

 

In any event, I need to reference in Net framework 4.0 (VS 2005 defaults to 2.0). Once I've addressed this I'll see if my issue has been resolved.

 

Thanks for the pointers. I'll get back either way.

Contributor
egcallis
Posts: 23
Registered: ‎09-14-2009
Message 13 of 24 (740 Views)

Re: Starting AutoCAD 2012 on a W7 64bit Machine from VS 2010 Express

12-29-2011 01:41 PM in reply to: egcallis

Well it looks like I need to goto VS 2010 as VS 2005 does not like Net 4 much. Bummer! I didn't address this issue but I would assume I have to use Net 4 since AutoCad 2012 uses it as well?

 

 

Contributor
egcallis
Posts: 23
Registered: ‎09-14-2009
Message 14 of 24 (718 Views)

Re: Starting AutoCAD 2012 on a W7 64bit Machine from VS 2010 Express

12-30-2011 06:52 AM in reply to: egcallis

Redid you sample C# code and  I get the same error at the new Acadapplication. Reinstalling the ObjectArx 2012.

Contributor
egcallis
Posts: 23
Registered: ‎09-14-2009
Message 15 of 24 (715 Views)

Re: Starting AutoCAD 2012 on a W7 64bit Machine from VS 2010 Express

12-30-2011 07:11 AM in reply to: egcallis

Reinstalled ObjectArx 2012 and it made no difference. Still get the same error at the

AcadApplication cad = New AcadApplication() line.

 

{"Retrieving the COM class factory for component with CLSID {6D7AE628-FF41-4CD3-91DD-34825BB1A251} failed due to the following error: 80080005 Server execution failed (Exception from HRESULT: 0x80080005 (CO_E_SERVER_EXEC_FAILURE))."} System.Exception

*Expert Elite*
norman.yuan
Posts: 987
Registered: ‎04-27-2009
Message 16 of 24 (711 Views)

Re: Starting AutoCAD 2012 on a W7 64bit Machine from VS 2010 Express

12-30-2011 07:25 AM in reply to: egcallis

I do not have VS2005 available any more. However, I think VS2004 is sufficient to do what you want - to automate Acad 2012 with a stand-alone exe.

 

1. Your app does not have to use the same version of .NET, because your app and Acad run in diferent processes.

2. AutoCAD 2012's NET API is actually .NET3.5, which is .NET2.0 based. It can work against .NET if its acad.exe.config has "<supportedRuntime version="v4.0"/>" in it.

 

Just saw your new post. So,

 

3. You do not need ObjectARX SDK. Since you do COM automation, I'd not recommand you set reference to Autodesk.AutoCAD.Interop/Commom to the ones from SDK. Rather, you set references to them in the COM tab of References dialog box, which are the ones registered by the AutoCAD installation. This would eliminate the slightest possibility of COM DLL HELL issue

 

You may try to start a clean and simple new project with VS2005 or VS2010 Express (to just verify the fact you can automate AutoCAD) by:

1. Start a new console project

2. Go to propect properties window to make sure target CPU is set to ANYCPU

3. Click "Add" reference, then do not browse, instead, click COM tab, find "AutoCAD 2012 type library", its file path should be something like "C:\Program files\Common files/Autodesk shared\acax18enu.tlb and select it as reference. Do not add reference to AutoCAD/ObjectDBX Common just yet (it is not needed to start AotuCAD instance);

4. After adding refernce to Autodesk.AutoCAD.Interop, if you select it Solution Explorer, in Properties Window, you can see its path actually points to the AutoCAD PIA in GAC (C:\Windows\Assembly....)

5. Then add following code:

 

using System;
using Autodesk.AutoCAD.Interop;

namespace AutomateAcad2012
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("Press any key to start AutoCAD");
            Console.ReadLine();

            Autodesk.AutoCAD.Interop.AcadApplication cad = new AcadApplication();
            cad.Visible = true;

            Console.WriteLine("Press any key to exit");
            Console.ReadLine();

            cad.Quit();
        }
    }
}

 and run.

 

As I said, I use VS2010. But for the code I showed here, I specifically set the project to target .NET2.0, (not 3.x or 4.0). It starts AutoCAD smoothly. That is, if you use VS2005, targeting .NET2.0, it should work.

 

 

Contributor
egcallis
Posts: 23
Registered: ‎09-14-2009
Message 17 of 24 (710 Views)

Re: Starting AutoCAD 2012 on a W7 64bit Machine from VS 2010 Express

12-30-2011 08:46 AM in reply to: norman.yuan

Okay, I tired this in VS2005, VS2010 Express and also VS 2010. Same result. I'm berginning to suspect that something else is buggered.

 

Question, I selected the Autocad ref by Com -> AutoCAD 2012 Type Library which shows the same path as in your last post. But when I look at the properties of the reference, it points to the GAC? What up with that?

 

Same type of Error at the cad = New ...;

 

Retrieving the COM class factory for component with CLSID {6D7AE628-FF41-4CD3-91DD-34825BB1A251} failed due to the following error: 80080005.

Contributor
egcallis
Posts: 23
Registered: ‎09-14-2009
Message 18 of 24 (710 Views)

Re: Starting AutoCAD 2012 on a W7 64bit Machine from VS 2010 Express

12-30-2011 08:49 AM in reply to: egcallis

Oops forget the GAC question.

Contributor
egcallis
Posts: 23
Registered: ‎09-14-2009
Message 19 of 24 (708 Views)

Re: Starting AutoCAD 2012 on a W7 64bit Machine from VS 2010 Express

12-30-2011 08:58 AM in reply to: egcallis

Just in case here is the VS 2010 project.

*Expert Elite*
norman.yuan
Posts: 987
Registered: ‎04-27-2009
Message 20 of 24 (706 Views)

Re: Starting AutoCAD 2012 on a W7 64bit Machine from VS 2010 Express

12-30-2011 09:01 AM in reply to: egcallis

Are you running your simple/clean console test app in your local computer as a regular logged in user? the error 0x80080005 usually means a security permission issue, such as trying to run AutoCAD by a service account.

 

Or you AutoCAD installation may be wrong. There is a post back just a little month old:

 

http://forums.autodesk.com/t5/NET/Unable-to-open-AutoCAD-2010-from-VB-NET-2020/m-p/3214236

 

that may help (but his error was 0x80040154).

Announcements
Are you familiar with the Autodesk Expert Elites? The Expert Elite program is made up of customers that help other customers by sharing knowledge and exemplifying an engaging style of collaboration. To learn more, please visit our Expert Elite website.
Need installation help?

Start with some of our most frequented solutions or visit the Installation and Licensing Forum to get help installing your software.