Automatically initialize VBA at AutoCAD startup (recent versions 2015+)

Automatically initialize VBA at AutoCAD startup (recent versions 2015+)

laurent.cadfr
Contributor Contributor
5,497 Views
14 Replies
Message 1 of 15

Automatically initialize VBA at AutoCAD startup (recent versions 2015+)

laurent.cadfr
Contributor
Contributor

Hello,

 

How can I automatically initialize VBA at AutoCAD startup (recent versions 2015+)?


I'm using AutoCAD P&ID 2016 and greater.
VBA does not initialize itself at AutoCad startup in despite of the following (compiled from many sources):
 - acad.arx mentionning acvba.arx (should initialize VBA but does'nt)
 - AcadStartup defined in acad.dvb 
 - acad.arx, acad.dvb are set in folder which is added to thrusted paths and support folders in preferences (Options)

 
Macro works fine only if I first launch a VBA command (eg.VBAMAN or VBAIDE...) which initialize VBA actually:


 >Command: VBAIDE
 >Initializing VBA System...    ' VBA inittialze after entering the command
 >VBA Startup Executing...    ' Prompt from my AcadStartup VBA code

 

May be my information is outdated? But could not find other in forums, or did I miss something in setup or SYS VARS??

 

Any suggestion?

Thanks in advance for help

0 Likes
Accepted solutions (1)
5,498 Views
14 Replies
Replies (14)
Message 2 of 15

Ed__Jobe
Mentor
Mentor

If you simply load a dvb using AcadApplication.LoadDVB(), it will initialize the vba environment as if you were running VBAMAN.

 

If you want to initialize, load the vba environment at startup without running any vba code, then you can create an ascii text file called acad.rx, similar to creating acad.lsp. Place the acad.rx file in the support file search path and add a line to the file with the following text:

 

acVba.arx

 

Depending upon your setup, you may need to add the full path to acvba.arx.

Ed


Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.
How to post your code.

EESignature

0 Likes
Message 3 of 15

laurent.cadfr
Contributor
Contributor

Thanks for your reply

 

As you understood from my explanations, I would like to initialize vba (load vba environment)  without running any code

 

I created the acad.rx file (in one folder from the support file search path) containing the text acvba.arx

 

The only difference with what tou suggested was the full path that I did not put

 

So, I did make the test changing the text in acad.arx:

I explicitly mentionned the full path: C:\Program Files\Autodesk\AutoCAD 2016\acvba.arx

 

But no change, VBA never initialize

note: I also tried doubling the \\ just in case... no change again!!!

 

Laurent

 

 

0 Likes
Message 4 of 15

Ed__Jobe
Mentor
Mentor

How do you know that vba isn't initializing? Remember that acad.rx will only run when you restart autoCAD.

 

Perhaps acad.rx is not being found. Do this Type the following at the command line.

(findfile "acad.rx")

 

If your file is in the support path, (findfile) should return the path where it found acad.rx. If it finds a file, make sure that it didn't find one in a different path. It wouldn't include the changes you made to your acad.rx file. If it returns (nil), then it didn't find your file.

Ed


Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.
How to post your code.

EESignature

0 Likes
Message 5 of 15

laurent.cadfr
Contributor
Contributor

Hello Ed,

 

I tested path as you told me:

 

>Command:
>Command: (findfile "acad.rx")
>"D:\\drawings\\autodesk-pnid\\vba\\acad.rx"
>Command: *Cancel*

 

The path is found, but AcadStartup still does not start!

 

What make me think VBA does not initialize is the fact I need a VBA command such as VBAIDE or VBAMAN (not loading any module,  just cancel then) to see the message refering to initialization:

 

>Command: VBAIDE
 >Initializing VBA System...    ' VBA initialize after entering the command
 >VBA Startup Executing...    ' Prompted from my AcadStartup VBA code

 

The only way I found to load is to use the acad.lsp/acaddoc.lsp containing lines below:

 

(vl-vbaload "D:\\DRAWINGS\\Autodesk-PnID\\VBA\\myPidUtils.dvb")
(vl-vbarun "InitializeVbaCommands")

 

Which appears to me as a workaround,  I still do not understand why using only acad.rx to initialize VBA does not work???

 

Feel intellectually frustrated 🙂

 

0 Likes
Message 6 of 15

Ed__Jobe
Mentor
Mentor

laurent.cadfr wrote:

 

Which appears to me as a workaround,  I still do not understand why using only acad.rx to initialize VBA does not work???

 


It could be the content of your acad.rx file is incorrect. Is the "acvba.arx" spelled correctly and do you have a return at the end of the line? It could still be true that the startup process is finding another acad.rx file first. You could search your hard drive for it. The first place it looks is the StartIn folder specified by the shortcut used to start AutoCAD,

Ed


Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.
How to post your code.

EESignature

0 Likes
Message 7 of 15

laurent.cadfr
Contributor
Contributor

Hello Ed,

 

First wish you a happy new year 2018...

 

Have been busy for some time so can reply only now...

 

Well, I have only one acad.rx file on the computer actually (I searched all locations)

And it the right one...

 

As it works using the acaddoc.lsp,  I put that question aside and unanswered for time being 😞

 

 

 

If anybody have idea please post...

0 Likes
Message 8 of 15

Ed__Jobe
Mentor
Mentor

Is the folder "D:\\drawings\\autodesk-pnid\\vba" in your search path? Options>Files tab>Support File Search Path

Ed


Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.
How to post your code.

EESignature

0 Likes
Message 9 of 15

laurent.cadfr
Contributor
Contributor

Hi Ed,

 

Yes the vba folder path wher all files are located is in the SFSP, I also moved it in top of list to be sure.

It has also been added to the trusted locations

0 Likes
Message 10 of 15

Ed__Jobe
Mentor
Mentor

You didn't answer my questions from post 6.

Ed


Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.
How to post your code.

EESignature

0 Likes
Message 11 of 15

laurent.cadfr
Contributor
Contributor

Hi Ed,

 

 

Sorry, missed it... yes I also checked acad.rx content which is "acvba.arx" followed by a CR-LF

 

 

I also made a new googling and  finally found a HotFix 4 for AutoCad 2016 :

 

Aug 05 2016: Accumulated hotfix 4 for AutoCAD 2016 based products

 

Extract from ReadMe:

The following issues are addressed by this hotfix:

  • ...
  • Certain VBA Macros throw an execution error.
  • ...

Seems to relate to VBA management !... so who knows...

I just checked and we still were in version 2016 SP1, I just installed hotfix 4, now appears as being version 2016 SP2

Not sure if it will actually adress my topic, what do  you think?

 

Will test it on next monday (it's now time for week-end)  if it changes something... will tell you then

 

To be continued... 🙂 

 

 

0 Likes
Message 12 of 15

laurent.cadfr
Contributor
Contributor
Accepted solution

Well,

no change in the situation, decided to change technology as I now needed to access Plant3D objects as well which cannot be accessed from VBA, I ported my utilities to VB.net and now load with no issue...

 

I close this Post with no solution to the initial problem

 

Message 13 of 15

Anonymous
Not applicable

Well, if you're still interested in knowing a solution even though you may not need it anymore, I think I've got one for you. I've actually had to do this with my own project.

 

To "initialize VBA" (which I assume to mean to load a .DVB file containing macros) from AutoCAD startup, you can add a command to C:\Program Files\Autodesk\AutoCAD 2018\Support\acad2018.lsp (C:\Program Files\Autodesk\AutoCAD [YEAR]\Support\acad[YEAR].lsp, for whatever version you're using). AutoCAD runs this whenever you create a new drawing file, so you can tell it to run a Lisp command to load the dvb. 

 

...
;;;LOAD DVB (VL-VBALOAD "C:/Folder/example.dvb")
...

I use the VL-VBALOAD command to prevent AutoCAD from displaying an error message if it tries to load the DVB and find that the DVB is already loaded.

 

If you are looking to run a specific macro at startup, I'm not 100% sure, but I would try either adding a VBARUN command in acad2018.lsp to run the macro at startup (which I kind of doubt will work), or go to your dvb and add a call to your macro/function from the drawing's "Activate" event. 

 

Even though I'm a little late, I hope this helps!

 

Message 14 of 15

laurent.cadfr
Contributor
Contributor

Thanks for your reply, I'm quite busy on another project now but will test as soon as I get some free time. i'll post results here.

Thanks again

0 Likes
Message 15 of 15

Anonymous
Not applicable

Thanks!)))

0 Likes