Jump to content

Load AutoCAD in VB.NET 'Cannot create ActiveX component.'


sanderson

Recommended Posts

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.

Link to comment
Share on other sites

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'~

Link to comment
Share on other sites

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'~

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

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 folder)

~'J'~

Link to comment
Share on other sites

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.ImportProfile(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!

Link to comment
Share on other sites

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 ?

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

  • 1 month later...

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?

Link to comment
Share on other sites

  • 1 month later...

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...