Author Topic: Vb6 and Set acadApp = GetObject(, "AutoCAD.Application")  (Read 705 times)

0 Members and 1 Guest are viewing this topic.

Lupo76

  • Bull Frog
  • Posts: 291
Vb6 and Set acadApp = GetObject(, "AutoCAD.Application")
« 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) ??

roy_043

  • Swamp Rat
  • Posts: 1450
  • BricsCAD 16
Re: Vb6 and Set acadApp = GetObject(, "AutoCAD.Application")
« Reply #1 on: January 27, 2017, 09:18:30 am »
Can you use this instead?:
Code: [Select]
Set acadApp = ThisDrawing.Application

57gmc

  • Newt
  • Posts: 55
Re: Vb6 and Set acadApp = GetObject(, "AutoCAD.Application")
« Reply #2 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.

Lupo76

  • Bull Frog
  • Posts: 291
Re: Vb6 and Set acadApp = GetObject(, "AutoCAD.Application")
« Reply #3 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

57gmc

  • Newt
  • Posts: 55
Re: Vb6 and Set acadApp = GetObject(, "AutoCAD.Application")
« Reply #4 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.

n.yuan

  • Bull Frog
  • Posts: 229
Re: Vb6 and Set acadApp = GetObject(, "AutoCAD.Application")
« Reply #5 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.

Lupo76

  • Bull Frog
  • Posts: 291
Re: Vb6 and Set acadApp = GetObject(, "AutoCAD.Application")
« Reply #6 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!