VBA
Discuss AutoCAD ActiveX and VBA (Visual Basic for Applications) questions here.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Createobject problem to AcadM 2011

12 REPLIES 12
Reply
Message 1 of 13
GVDB
1344 Views, 12 Replies

Createobject problem to AcadM 2011

Hello,

 

I've a program written in VB6 which starts Autocad:

 

Public oAcadApp As AcadApplication

Set oAcadApp = CreateObject("AutoCAD.Application.18.1")

 

on a PC with XP 32 bit there is no problem but on a PC with XP 64 bit -> oAcadApp stays Nothing, while Autocad does start up properly.

 

Do I miss something? Is there a difference between 32 bit and 64 bit for VB6?

 

Regards,

 

Geert

 

 

12 REPLIES 12
Message 2 of 13
jsurpless
in reply to: GVDB

I've got a similar problem...

 

I'm using 'AutoCAD_Instance = CreateObject("AutoCAD.Application")' to open AutoCAD... I'm not including the version because my company upgrades every year and I don't want to have to re-issue the app each time...

 

On WinXP, one user has both 2011 and 2010 installed... it works perfectly, opening the last version opened (same as double-clicking on a dwg file in Windows)... but in Vista, I get the error you mentioned...

 

Any thoughts?

Message 3 of 13
GVDB
in reply to: jsurpless

hi, my solution was to declare:

 

Public oAcadApp As Object -> instead of AcadApplication

 

Good luck,

 

Kind regards,

 

Geert

Message 4 of 13
jsurpless
in reply to: GVDB

Yeah, I've got that done - works fine with XP (and apparently Windows 7) but not Vista...

Message 5 of 13
GVDB
in reply to: jsurpless

We only use XP - 32 bit and Win7 - 64 bit so with Vista I can't help you.

On Win7 - 64 bit it works with Object, but it's a workaround at the problem and isn't a nice solution.

But it works for me.

 

Geert

Message 6 of 13
natanaelfractus
in reply to: GVDB

I change it too and still doesn't work. I on Windows 8.1 64 bit, VB 2013 tryng to run an instance of Autocad 2014 64 bit.
The Acad.exe runs on task manager but after a little it stops and the next line of code gets an exeption

 

'doesn't work

Public AcadApp As Object

AcadApp = CreateObject("AutoCAD.Application")
AcadApp.Visible = True

 

'doesn't work

Dim AcadApp As Object

AcadApp = CreateObject("AutoCAD.Application")
AcadApp.Visible = True

 

'doesn't work

Dim AcadApp As AutoCAD.AcadApplication

AcadApp = CreateObject("AutoCAD.Application")
AcadApp.Visible = True

Message 7 of 13

Hi,

 

>> The Acad.exe runs on task manager but after a little it stops and the next line of code gets an exeption

A few questions to make your issue more clear to us:

  • Where is the VBA code running? In an Excel or Word or ...VBA? 32bit or 64bit?
  • When you say "Acad.exe runs" ... was it running before you started your code or did it start when you started your code?
  • When you say "gets an exception" ... what exception do you get?
  • When you say "next line of code" ... what is the "next line" for you?

 

One syntax issue might exist: change your line with "CreateObject" according to that:

   Set AcadApp = CreateObject("AutoCAD.Application")

 

- alfred -

------------------------------------------------------------------------------------
Alfred NESWADBA
Ingenieur Studio HOLLAUS ... www.hollaus.at ... blog.hollaus.at ... CDay 2024
------------------------------------------------------------------------------------
(not an Autodesk consultant)
Message 8 of 13

I'm sorry for posting everywhere, that's my first time on forums. The answers are:

 

1- the code is running in visual studio 12 (2013), I think its 32 bit because its installed on x86 program files

2-acad.exe is closed before and when i run my program it starts running acad.exe on task manager then after a moment it closes itself and then i got the exeption on visual studio

3-the next line of the code is "visible = true" or "acadapp.visible = true"

4-the exception is:

 

"An unhandled exception of type 'System.Runtime.InteropServices.COMException' occurred in BasicApp01.exe

Additional information: The server threw an exception. (Exception HRESULT: 0x80010105 (RPC_E_SERVERFAULT))"

 

5-I tryied adding "Set" before that line of code but visual studio delete it automatically and I can run Excel normally without it

my entire code is:

 

Dim AcadApp As AutoCAD.AcadApplication

AcadApp = CreateObject("AutoCAD.Application")
AcadApp.Visible = True

 

6-I already added the references for autocad too.

7-I have tried adding AutCad.Application.19 and it won't work either

 

I think i got an exeption because there is no acad.exe running to make visible, so the problem must be in the "CreateObject" line.

 

tank you.

Message 9 of 13

Hi,

 

>> the code is running in visual studio 12 (2013)

Ok, it's not VBA (as the initial poster mentioned in his first problem description). And yes, with VB.NET the "Set" is not necessary as I suggested previously.

 

>> I think its 32 bit because its installed on x86 program files

No, the directory where Visual Studio is installed does not give you the info about the environment your developed/compiled EXE is running. If your EXE is running in 64bit- or 32bit-mode depends only on your project settings.

 

>> 2-acad.exe is closed before and when i run my program it starts running acad.exe

>> 3-the next line of the code is "visible = true" or "acadapp.visible = true"

>> [...] so the problem must be in the "CreateObject" line

Set a breakpoint at the line with .Visible, start your exe, let your code wait at the break point and see (in the taskmanager) if the process ACAD.EXE stays alive as long as your code does not execute the codeline with .Visible. Execute your code then line-by-line, just to know if AutoCAD stops at the line with .Viisible or AutoCAD stops at the end of your sub (as the variable for the AcadApplication get's destroyed).

 

I have attached a sample (as simple as possible), that works for me and should work for you too.

 

- alfred -

------------------------------------------------------------------------------------
Alfred NESWADBA
Ingenieur Studio HOLLAUS ... www.hollaus.at ... blog.hollaus.at ... CDay 2024
------------------------------------------------------------------------------------
(not an Autodesk consultant)
Message 10 of 13

Hi, Alfred

 

>>No, the directory where Visual Studio is installed does not give you the info about the environment your developed/compiled EXE is running. If your EXE is running in 64bit- or 32bit-mode depends only on your project settings.

 

I did i little search at the program but i really don't know where I can see if the program is setted up as x86 or x64. I'm looking at google but so far I did not find out how to.

 

>>Set a breakpoint at the line with .Visible, start your exe, let your code wait at the break point and see (in the taskmanager) if the process ACAD.EXE stays alive as long as your code does not execute the codeline with .Visible.

 

I did this and the acad.exe does not stay alive with the break point at .Visible

 

>>Execute your code then line-by-line, just to know if AutoCAD stops at the line with .Viisible or AutoCAD stops at the end of your sub (as the variable for the AcadApplication get's destroyed)

 

As I could not find line-by-line run option like in Office VBA Editor with the F8 key (I did not found it on google either how to, I guess it doesn' have this option) so I set up breakpoints and use F10 (Step Over) e F11 (Step Into) keys. It's not the same result to make a clear answer if it shuts before the End Sub or with it.

 

>>I have attached a sample (as simple as possible), that works for me and should work for you too.

 

The program you sent me is pretty much what I want to do but it didn't work either. When I run it I got an error window saying: Error during initialization of AutoCAD: Failed remote procedure call (Exception of HRESULT: 0x800706BE and acad.exe also stops running. I did set breakpoints in your code too and the result was the same. Your program worked for you with the same enviroment configurations? (Windows 8.1 64bit, Autocad 2014 64bit)

 

Tanks for the help 🙂

Message 11 of 13

Hi,

 

>> I did i little search at the program but i really don't know where I can see if the program is setted up as x86 or x64

Within Visual Studio right-click the project ==> properties, goto tab "Compile" and there you find "Target CPU", that is where to set the mode to 32bit, 64bit or make it depending on the operating system.

 

>> As I could not find line-by-line run option [...]

>> so I set up breakpoints and use F10 (Step Over) e F11 (Step Into) keys

You found <F10> and <F11>, so you found the option to run every single line separately 😉

 

>> Your program worked for you with the same enviroment configurations? (Windows 8.1 64bit, Autocad 2014 64bit)

I used my EXE with AutoCAD 2015, not 2014, but I don't think that this will make a difference.

 

BTW: have you ever started a repair installation of your AutoCAD?

 

- alfred -

------------------------------------------------------------------------------------
Alfred NESWADBA
Ingenieur Studio HOLLAUS ... www.hollaus.at ... blog.hollaus.at ... CDay 2024
------------------------------------------------------------------------------------
(not an Autodesk consultant)
Message 12 of 13

Alfred, I found out what was the problem:

 

When I first installed AutoCAD I did some mods to improve performance and one of them was stoping AutoCAD from creating a Drawing1.dwg on startup. When I enabled it again everything worked out. Thank you very much for the help.

 

Natanael =D

Message 13 of 13

Hi,

 

>> I did some mods to improve performance and one of them was stoping AutoCAD from creating a Drawing1.dwg

thank you for your feedback!

 

- alfred -

------------------------------------------------------------------------------------
Alfred NESWADBA
Ingenieur Studio HOLLAUS ... www.hollaus.at ... blog.hollaus.at ... CDay 2024
------------------------------------------------------------------------------------
(not an Autodesk consultant)

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

Post to forums  

Autodesk Design & Make Report

”Boost