TheSwamp

Code Red => VB(A) => Topic started by: Lupo76 on January 26, 2017, 02:05:02 PM

Title: Vb6 and Set acadApp = GetObject(, "AutoCAD.Application")
Post by: Lupo76 on January 26, 2017, 02:05:02 PM
Hello to all,
Many years ago I wrote an application in VB6 and compiled an EXE file.
It worked very well and it still works in BricsCAD.

However in AutoCAD 2016 and Windows 7 64 bit it does not work.
My sense is that the problem is the 64-bit Windows.

Unfortunately I'm very rusty in VB6, as they are years that do not use this programming language :-(

This is the code I wrote:

Code: [Select]
            If UserForm7.Option1.Value = True Then
                'AutoCAD FULL
                MsgBox "AutoCAD"
                Set acadApp = GetObject(, "AutoCAD.Application")
             Else
                'BricsCAD
                MsgBox "BricsCAD"
                Set acadApp = GetObject(, "BricscadApp.AcadApplication")
            End If
           
            acadApp.Visible = True
             
            Dim acadDoc As Object
            Set acadDoc = acadApp.ActiveDocument
         

            ReturnPnt = acadDoc.Utility.getpoint(, "Point base: ")

Is there some way to make it work in AutoCAD is Windows 7 (64-bit) ??
Title: Re: Vb6 and Set acadApp = GetObject(, "AutoCAD.Application")
Post by: roy_043 on January 27, 2017, 09:18:30 AM
Can you use this instead?:
Code: [Select]
Set acadApp = ThisDrawing.Application
Title: Re: Vb6 and Set acadApp = GetObject(, "AutoCAD.Application")
Post by: 57gmc on January 27, 2017, 10:11:09 AM
@roy, No, it wouldn't work.

@Lupo
Yes Win7 is 64 bit, but more importantly, acad 2016 is 64 bit. It also uses VBA7 (which you will need to install for it to respond to your code). If you type VBAMAN at the prompt, you will get an error dialog with a link to download the vba install. You will also need to upgrade Visual Studio. There are free versions, so there's no need to continue using VB6.
Title: Re: Vb6 and Set acadApp = GetObject(, "AutoCAD.Application")
Post by: Lupo76 on January 27, 2017, 10:23:47 AM
Perhaps, I have found a solution and without installing VBA.
The application is in fact written in VB6 and no VBA.

If the solution I've found it works correctly and exceeds the last test I'll be back here to bring it back
Title: Re: Vb6 and Set acadApp = GetObject(, "AutoCAD.Application")
Post by: 57gmc on January 27, 2017, 10:37:46 AM
Possibly acad cad respond to COM calls without vba installed. I haven't tried it. But you still may need a more current version of VB.
Title: Re: Vb6 and Set acadApp = GetObject(, "AutoCAD.Application")
Post by: n.yuan on January 27, 2017, 10:38:42 AM
Since you run stand-alone EXE to automate AutoCAD as out-process instance, it should not matter that your app is 32-bit EXE app and AutoCAD (2016) is 64-bit app. However, the code you show is used in the VB6 app as is, it would ONLY work when AutoCAD (or BricsCAD) has already been running (i.e. an running instance of AcadApplication instance must exist) in the same computer. If not, your code would raise exception at this line

acadApp.Visible = True

and crash your EXE app.
Title: Re: Vb6 and Set acadApp = GetObject(, "AutoCAD.Application")
Post by: Lupo76 on January 27, 2017, 12:46:54 PM
The code that I put in the first message is correct.
I did some tests on other PCs and working properly.

However, if in the PC, are installed AutoCAD and BricsCAD the code requests must specify the AutoCAD version.
Eg.

Code: [Select]
Set acadApp = GetObject(, "AutoCAD.Application.20.1")

PS. No need to install VBA!
Title: Re: Vb6 and Set acadApp = GetObject(, "AutoCAD.Application")
Post by: zzyong00 on October 20, 2017, 11:13:27 AM
try:run as administrator
Title: Re: Vb6 and Set acadApp = GetObject(, "AutoCAD.Application")
Post by: gps77 on November 09, 2017, 03:29:56 PM
Hello All,

These are the links that finally helped me solve the problem. Make sure to set the CLSID and the AutoCAD.Application.21 (the number) to the appropriate AutoCAD version (this one is for Autocad 2017). Look for it in the registry. It even works with visual basic 5 and 64bit AutoCAD 2017 on Windows 10.

https://stackoverflow.com/questions/40656440/vb6-program-interacting-with-autocad-is-not-longer-able-to-create-or-bind-to-t (https://stackoverflow.com/questions/40656440/vb6-program-interacting-with-autocad-is-not-longer-able-to-create-or-bind-to-t)
https://stackoverflow.com/questions/9125424/late-binding-run-time-error-in-vb6-when-creating-an-object-from-a-net-assembly (https://stackoverflow.com/questions/9125424/late-binding-run-time-error-in-vb6-when-creating-an-object-from-a-net-assembly)

Code: [Select]

Windows Registry Editor Version 5.00

[HKEY_CLASSES_ROOT\AutoCAD.Application.21]
@="AutoCAD Application 21"

[HKEY_CLASSES_ROOT\AutoCAD.Application.21\CLSID]
@="{0D327DA6-B4DF-4842-B833-2CFF84F0948F}"

[HKEY_CLASSES_ROOT\AutoCAD.Application]
@="AutoCAD Application"

[HKEY_CLASSES_ROOT\AutoCAD.Application\CLSID]
@="{0D327DA6-B4DF-4842-B833-2CFF84F0948F}"

[HKEY_CLASSES_ROOT\AutoCAD.Application\CurVer]
@="AutoCAD.Application.21"

[HKEY_LOCAL_MACHINE\SOFTWARE\Classes\AutoCAD.Application.21]

[HKEY_LOCAL_MACHINE\SOFTWARE\Classes\AutoCAD.Application.21\CLSID]
@="{0D327DA6-B4DF-4842-B833-2CFF84F0948F}"

[HKEY_LOCAL_MACHINE\SOFTWARE\Classes\AutoCAD.Application]
@="AutoCAD Application"

[HKEY_LOCAL_MACHINE\SOFTWARE\Classes\AutoCAD.Application\CLSID]
@="{0D327DA6-B4DF-4842-B833-2CFF84F0948F}"

[HKEY_LOCAL_MACHINE\SOFTWARE\Classes\AutoCAD.Application\CurVer]
@="AutoCAD.Application.21"