PDA

View Full Version : Load AutoCAD in VB.NET 'Cannot create ActiveX component.'



sanderson
8th Mar 2010, 06:55 pm
For some strange reason, I'm having a struggle to launch AutoCAD. I am getting the error 'Cannot create ActiveX component.' for this code, here... acadapp2009 = CreateObject("AutoCAD.Application.17.2")

Imports Autodesk.AutoCAD.Interop
Imports Autodesk.AutoCAD.Interop.AcadDocumentClass
Imports Autodesk.AutoCAD.Interop.Common

PublicClass Form1
' Public WithEvents AcadApp2009 As Autodesk.AutoCAD.Interop.AcadApplication
' Public acadapp2009 As Autodesk.AutoCAD.Interop.AcadApplication
Public acadapp2009 AsObject



PublicSub LoadProfile(ByVal ProfileName AsString, ByVal ProfileFile AsString)
Try
acadapp2009 = GetObject(, "AutoCAD.Application.17.2")
Catch ex As Exception
acadapp2009 = CreateObject("AutoCAD.Application.17.2")
EndTry
Dim acaddoc As Autodesk.AutoCAD.Interop.AcadDocument = AcadApp2009.ActiveDocument
With AcadApp2009.Preferences.Profiles
.importfile(ProfileName, ProfileFile, True)
EndWith
EndSub

The same code works great with AutoCAD 2006 - version 16.

Strange, because the application does open, but the code stops and errors out. Do I need to add a timeout, or do until somewhere?


Thanks in advance for the help.

fixo
8th Mar 2010, 07:03 pm
For some strange reason, I'm having a struggle to launch AutoCAD. I am getting the error 'Cannot create ActiveX component.' for this code, here... acadapp2009 = CreateObject("AutoCAD.Application.17.2")

Imports Autodesk.AutoCAD.Interop
Imports Autodesk.AutoCAD.Interop.AcadDocumentClass
Imports Autodesk.AutoCAD.Interop.Common

PublicClass Form1
' Public WithEvents AcadApp2009 As Autodesk.AutoCAD.Interop.AcadApplication
' Public acadapp2009 As Autodesk.AutoCAD.Interop.AcadApplication
Public acadapp2009 AsObject



PublicSub LoadProfile(ByVal ProfileName AsString, ByVal ProfileFile AsString)
Try
acadapp2009 = GetObject(, "AutoCAD.Application.17.2")
Catch ex As Exception
acadapp2009 = CreateObject("AutoCAD.Application.17.2")
EndTry
Dim acaddoc As Autodesk.AutoCAD.Interop.AcadDocument = AcadApp2009.ActiveDocument
With AcadApp2009.Preferences.Profiles
.importfile(ProfileName, ProfileFile, True)
EndWith
EndSub

The same code works great with AutoCAD 2006 - version 16.

Strange, because the application does open, but the code stops and errors out. Do I need to add a timeout, or do until somewhere?


Thanks in advance for the help.


Type in the command line: (getvar "acadver")
You could see the current version of your AutoCAD -
take a look at the fist 3 digits

~'J'~

sanderson
8th Mar 2010, 08:02 pm
17.2s, so I velieve 17.2 is correct! Remember, AutoCAD does load, but not until after the error appears.

fixo
8th Mar 2010, 08:31 pm
17.2s, so I velieve 17.2 is correct! Remember, AutoCAD does load, but not until after the error appears.

Again just an idea only, do you sure that you have a
point to the correct versions of acmgd.dll and
acmgdinternal.dll and set 'Copy Local' mode to false?
Please, check it

~'J'~

sanderson
8th Mar 2010, 09:15 pm
Thanks for the info, but I don't get it. The program references AXDBLib (Autodesk.AutoCAD.Interop.Commom) and AutoCAD (Autodesk.AutoCAD.Interop). They are both for version 2009 (17.2s) What are these other dll files for? And what / where is the 'Copy Local' mode setting?

fixo
8th Mar 2010, 09:30 pm
Thanks for the info, but I don't get it. The program references AXDBLib (Autodesk.AutoCAD.Interop.Commom) and AutoCAD (Autodesk.AutoCAD.Interop). They are both for version 2009 (17.2s) What are these other dll files for? And what / where is the 'Copy Local' mode setting?

Here is citation:

Go toscreen References tab, double-click on acdbmgd.dll to display its Properties, and set Copy Local to False. (This is to ensure your .NET add-in loads the copy of
acdbmgd.dll stored in the AutoCAD folder and doesn’t
added to \\bin (file://\\bin) folder)
~'J'~

Kerry Brown
9th Mar 2010, 12:50 am
I won't do VB,
but is the different spelling of AcadApp2009 critical to you ??

Kerry

sanderson
9th Mar 2010, 03:20 pm
There is an MFC Mode property. Is this what you mean?

sanderson
9th Mar 2010, 03:21 pm
AcadApp2009 is just a variable.

sanderson
9th Mar 2010, 05:58 pm
Okay, here's my code.
I still am getting same ActiveX error. I simply need to load AutoCAD
The program works great if I load AutoCAD manually.
I need to do a quit, yes at the end. Is there a way to do this??

PublicSub LoadProfile(ByVal ProfileName AsString, ByVal ProfileFile AsString)
Dim acadapp2009 As AcadApplication
acadapp2009 = CreateObject("AutoCAD.Application.17.2")
DoUntil Err.Number = 0
' Wait for instance of AutoCAD to load
Loop
Dim acaddoc As Autodesk.AutoCAD.Interop.AcadDocument = acadapp2009.ActiveDocument
Dim acadPref As AcadPreferencesProfiles = acaddoc.Application.Preferences.Profiles
If acadPref.ActiveProfile = "Despatch2k9"Then
lstStatus.Items.Add("Despatch2k9 is already loaded.")
Else
acaddoc.Application.Preferences.Profiles.ImportPro file(ProfileName, ProfileFile, False)
acadPref.ActiveProfile = "Despatch2k9"
lstStatus.Items.Add("Despatch2k9 is imported and activated.")
EndIf
acaddoc.Application.Quit() ' Need to apply 'yes'
EndSub

Thanks for the help!

Kerry Brown
10th Mar 2010, 06:03 am
AcadApp2009 is just a variable.

Yes, I realise that.

What I asked is "is the different spelling of AcadApp2009 critical" in VB
ie.
is acadapp2009 the same as AcadApp2009 in VB ?

sanderson
10th Mar 2010, 04:07 pm
I have changed all the case sensitivity.. There may have been some comments. NET self-corrects this to the name that is declared.

Anyhow, if you have any thoughts, I would appreciate it. The program cannot create the ActiveX object because it is waiting for AutoCAD to open, yet AutoCAD does open. When AutoCAD is open, the program works.

I'm also looking for a way to quit without saving out of the application.

Thanks for your help thus far.

shirazbj
16th Mar 2010, 01:27 pm
I think the program only tends to setup the comunication with AutoCAD ActiveX but not AutoCAD itself. After AutoCAD started, it registed its ActiveX somewhere in the operation system, so other program could contact it. So you must start AutoCAD first.

I once use VBA under Excel to comunicate with AutoCAD. It has the same problem. If I changed the name to ACAD.exe for example in the setup sentence in the program, AutoCAD started, but no ActiveX connection then.

Quite interested in using .net to comunicated with AutoCAD. Don't know if VB 2008 Express could do this work?

yoannmaingon
3rd May 2010, 07:24 pm
Is this issue solved?
i have almost the same issue i guess. I am trying to start Autocad 2011 from Javascript/activex.
It fails but, if i debug it, and i go step by step on the commands it works.
So i was also thinking of having some kind of Timer. But i didn't find the solution yet.

any idea?

FunkyFresh
4th Jun 2010, 02:52 pm
same problem here too. only happens on windows 7 64bit