.NET
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

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

23 REPLIES 23
Reply
Message 1 of 24
egcallis
1171 Views, 23 Replies

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

Target Platform is W7 64bit running AutoCAD 2012. Development is with VS 2010 Express.

 

We have a VBA routine the we have been using for 5 years to convert DXFs produced by another 3D package into DWGS. Basically, the program cyles through all the *.dxfs in a folder and changers entitties's layers, colors, modifies text widths, and then scales all by a certain factor.

 

So I've created a VS 2010 Express Windows Application to do this from outside of AutoCad (I couldn't get the code to work as a DLL inside of AutoCAD).

 

Questions:

 

1. Can I use VS 2010 Express to create this application?

  a. If yes, how fo I tell VS 2010 Express to compile for 64bit?

  b. What is the Syntax to start an AutoCAD Application?

 

2. If the answer to 1 is no, can I use VS 2005 Professional to create it?

 

Assuming one of the above answers is yes, which Autodesk components do I need to reference in my VS project?

 

Yes, I've searched this forum for help, but AutoCAD 2012 combined with 64 bit has considerably muddied the waters for me.

 

Fianally, I'm sure I can convibce my boss to upgrade my VS 2005 to 2010 if needed, but don't want to unless it would solve most of the issues. I use VS 2005 for other programs and they compile fine on the 64bit machine I'm using.

 

 

23 REPLIES 23
Message 2 of 24
Alfred.NESWADBA
in reply to: egcallis

Hi,

 

I tried to search >>>click<<< and one of the first answers point to >>>that link<<< 😉

 

Good luck, - alfred -

------------------------------------------------------------------------------------
Alfred NESWADBA
Ingenieur Studio HOLLAUS ... www.hollaus.at ... blog.hollaus.at ... CDay 2024
------------------------------------------------------------------------------------
(not an Autodesk consultant)
Message 3 of 24
egcallis
in reply to: Alfred.NESWADBA

Alfred, I've been there but I'm not doing a class dll. And this article dosen't address 64bit issues.

Message 4 of 24
Alfred.NESWADBA
in reply to: egcallis

Hi,

 

>> but I'm not doing a class dll

But that's what you need, also your info "I couldn't get the code to work as a DLL inside of AutoCAD" was a question, wasn't it?

Could you describe how your previous app worked? Was it an external EXE that used AutoCAD via ActiveX/COM?

 

>> And this article dosen't address 64bit issues

It's not necessary for most AutoCAD-dotNET-apps to differentiate between 32bit and 64bit, you can leave the project settings set to "Any CPU" and it will work ... once more: valid for dotNET-DLLs!

 

- alfred -

------------------------------------------------------------------------------------
Alfred NESWADBA
Ingenieur Studio HOLLAUS ... www.hollaus.at ... blog.hollaus.at ... CDay 2024
------------------------------------------------------------------------------------
(not an Autodesk consultant)
Message 5 of 24
egcallis
in reply to: Alfred.NESWADBA

No, the DLL inside Autocad was a statement not a question.

 

If you don't use VS2010 Express on a 64bit machine then why are you responding? In other words, we need to seperate issues.

 

For clarity, I'm doing a standalone application that will start an autocad session, do its thing, then close the autocad session.

 

Eric

Message 6 of 24
Alfred.NESWADBA
in reply to: egcallis

>> If you don't use VS2010 Express on a 64bit machine then why are you responding?

Sorry for that, I just tried to help. ;(

 

- alfred -

------------------------------------------------------------------------------------
Alfred NESWADBA
Ingenieur Studio HOLLAUS ... www.hollaus.at ... blog.hollaus.at ... CDay 2024
------------------------------------------------------------------------------------
(not an Autodesk consultant)
Message 7 of 24
egcallis
in reply to: Alfred.NESWADBA

If that came across as mean, it was not intended that way. Just want to spend both our resources in an economical way.

Message 8 of 24
norman.yuan
in reply to: egcallis

If your goal is to create a stand-alone exe app that automates AutoCAD, yes, VS2010 Express can be used with Acad2012 64-bit, so is VS2005.

 

In general, or by default, a .NET app is built to target ANY CPU, unless you specifically want to limit the app to be built to traget x86, x64 or Itanium. In your case, if you leave pour app targeting ANY CPU, you would not have to worry whether your app runs in Win64 or Win32.

 

Also, in your case, even you build your app specifically for x86 CPU, it still runs with Win64, and it can STILL automate 64-bit AutoCAD, beause it is out-process automation, that is, automated AutoCAD does not run in the same process as your app.

 

The possible issue of COM automation as you planned depends on what is your app's dependecies. Some COM objects used in your app may not be presents/or be the same in the user computer, due to COM's "DLL Hell" issue. And of course, you are limited to AutoCAD's COM API only to automate AutoCAD.

 

Following code is a console app, where I have no issue to start AutoCAD (Acad2012 64-bit)

 

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

 

If the running computer has more than one version of AutoCAD installed, you would likely have some issue. Yes, COM "DLL Hell" is certainly possble reason, even the PIA (Autodesk.AutoCAD.Interop/Common may seems co-exist in GAC with different versions, but the underline COM DLL the PIA wraps can only be one version, the latest AutoCAD version installed. If your user may use different version of AutoCAD, you'd better ONLY install the oldest version in your development box and develop against it, be it that you use late-binding or not.

 

I am not sure why you refuse to consider doing things inside AutoCAD and insist on out-process automation, considering your previous app is VBA that runs inside AutoCAD. In most cases, automating Acad from stand-alone app is bad choice in comparison to do the same thing inside AutoCAD, unless the automation process is very simple. You need a lot of code to make sure AutoCAD is properly available in the running machine before your task can be performed. While when running inside AutoCAD, when your app can start directly onto your task.

 

Message 9 of 24
egcallis
in reply to: norman.yuan

We did it in AutoCAd before because it was easier to develop that way. But all the code does is as listed in my first post. Since we are producing the dxfs from another application, it makes since to me to have them be converted via automation rather than manually opening AutoCad, doing the conversion, then closing autocad.

 

But thanks for the post. Couple of questions:

 

1. What are your project's references?

2. Was this done with VS 2010 Express? If so, any special options?

 

Running the following code gives the error:

+  ex {"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

 

 

Code Snippet

Imports Autodesk.AutoCAD.Interop

Imports Autodesk.AutoCAD.Interop.Common


Public ClassMainForm

   

   Public AcadApp AsAcadApplication

   

   Public Sub StartAutoCADSession()       

      Try

                   AcadApp = New AcadApplication() <- Hangs for like 30 secs, then errors

                   AcadApp.Visible =  True

      Catch ex AsException

                   AcadApp = Nothing

               EndTry   

EndSub

 

I attached the project so you can see all the particulars.

 

Thanks again, I'll be googling the error.

Message 10 of 24
egcallis
in reply to: egcallis

Another note. Task Manager shows that AutoCad starts. The process is stopped after I stop debugging (after the exception).

Message 11 of 24
norman.yuan
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.

 

 

Message 12 of 24
egcallis
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.

Message 13 of 24
egcallis
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?

 

 

Message 14 of 24
egcallis
in reply to: egcallis

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

Message 15 of 24
egcallis
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

Message 16 of 24
norman.yuan
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.

 

 

Message 17 of 24
egcallis
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.

Message 18 of 24
egcallis
in reply to: egcallis

Oops forget the GAC question.

Message 19 of 24
egcallis
in reply to: egcallis

Just in case here is the VS 2010 project.

Message 20 of 24
norman.yuan
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).

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk DevCon in Munich May 28-29th


Autodesk Design & Make Report

”Boost