Peculiar DVB Loading Problem

Peculiar DVB Loading Problem

Anonymous
Not applicable
2,840 Views
1 Reply
Message 1 of 2

Peculiar DVB Loading Problem

Anonymous
Not applicable

Hello! I'm pretty familiar with VBA, but I have an interesting and specific problem for which I don't have a good solution. I have 2 commands added to my startup acad2018.lsp file: one for loading a DLL containing many method definitions and calls to VBA macros I've created (loaded using netload) and the other for loading a DVB containing many macros I've created (loaded using vl-vbaload). Both of these files are loaded when AutoCAD starts up, so I used the vl-vbaload command to prevent a message from popping up every time it tries to load a DVB that is already loaded.

 

I have a VBA macro that publishes several paperspace layouts within my drawing to PDF by means of configuring a DSD file and then sending the PUBLISH command to print from that DSD. When plotting (with background plot disabled, which is apparently necessary for this kind of plot), AutoCAD reloads and plots each sheet until it has plotted them all.

 

The problem is that, after my sheets print to PDF, AutoCAD loads another instance of my DVB file. It seems that AutoCAD runs through its startup routine after publishing. And somehow, AutoCAD doesn't recognize that the DVB loaded at startup was already loaded and it loads two instances of the same DVB, which is causing issues when trying to use the macros stored in the DVB. I thought that the vl-vbaload command would have prevented this, but it doesn't appear to. 

 

As of right now, I've been able to take advantage of my DLL (which calls my print macro) to retroactively handle this. My DLL contains a command method that invokes the print macro, and I am able to unload one instance of the DVB after telling AutoCAD to run the macro, but I don't care for this method. Because I use the SendCommand() (asynchronous) method to publish from within my macro, AutoCAD publishes after all of my code stops running. So I've been able to unload the original DVB first and then let it publish and load the DVB again. Surely this is not the way to do it. 

 

Does anyone know why or how my DVB is getting loaded again and how to prevent it? Any better ideas than mine on how to work around this issue? Any help is greatly appreciated!

0 Likes
Accepted solutions (1)
2,841 Views
1 Reply
Reply (1)
Message 2 of 2

norman.yuan
Mentor
Mentor
Accepted solution

The problem of your *.dvb fiel being repeatedly reloaded is due to the fact that you have (vl-vbaload ...) in acaddoc20xx.lsp file.

 

Firstly, you do not mess with acad20xxx.lsp and acaddoc20xx.lsp file. Notice that they are in %program files\Autodesk\AutoCAD 20xx\" folder, and are meant only being used by Autodesk with its specific AutoCAD and its verticals version. To customize your own code execution on AutoCAD start-up/document open-up, you should use acad.lsp and acaddoc.lsp. By default they are in user's window profile location (c: users\[username]\appdata\roaming\autodesk\...."), or you can place them in anywhere accroding to your office's CAD resources setup configuration, as long as they can be found in AutoCAD's support paths.

 

Now, it is the cause of your issue: acaddoc.lsp (or acaddoc20xx.lsp, but you should not touch it as aforementioned) is executed on EVERY JUST-OPEN drawing, while acad.lsp only executes once on AutoCAD startup by tradition. By saying "by tradition", it used to be only being executed once on AutoCAD startup, by quite a years ago, AutoCAD also allows acad.lsp be configured to be executed when opening each drawing (to configure it, go to "Options->System->Security..."). However, since there is acaddoc.lsp is specifically for code-execution on each document, there is little point to configure acad.lsp to do so.

 

So, in your code, if you want to make sure your VBA (*.dvb) being loaded on AutoCAD start-up, you simply place the (vl-vbaload ....) lisp statement in acad.lsp file (and double check the "Options..." to make sure acad.lsp only executes on AutoCAD startup.

 

Actually, with lisp function (vl-xxxx), you do not even load *.dvb file in order to execute an VBA macro: instead of (vl-vbaload "[path to DVB file]"), you can simply use (vl-vbarun "c:/my VBA folder/myVBAProject.dvb!Module1.myMacro"). What "vl-vbarun" does is it will check if the VBA project is loaded or not, if not, load it, and then run the macro.

 

In my practice before (we almost do not use VBA any more), we never need to load VBA on AutoACD startup. and for each menu item/toolbar button that runs VBA macro, we assign a macro to the menu item/toolbar button via CUI with this macro code: ^C^C(vl-vbarun "xxxxxxx.dvb!module.macro"), as long as the "xxx.dvb" can be found via support paths.

 

 

Norman Yuan

Drive CAD With Code

EESignature

0 Likes