autoload vba

autoload vba

Anonymous
Not applicable
735 Views
13 Replies
Message 1 of 14

autoload vba

Anonymous
Not applicable
I want to load some VBA routines each time a drawing is opened (without using an "acad.dvb" file). I know I can do this in an "acaddoc.lsp" file with a few lines that look something like this: (if (findfile "perry.dvb") (command "_-vbaload" "perry") (alert "personal VBA not loaded.") ) The problem with this approach is that upon opening subsequent drawings I get an alert box stating that the vba module is already loaded. With autolisp files I can use a line like this: (defun C:LM () (if (not c:lman)(load "lman"))(c:lman)) which will fist check if the routine is already loaded, then load and execute if it is not. So my question is can I do something similiar with VBA? Something along the line of: (if (not VBAPROJECTNAME)(vbaload "VBAPROJECTNAME"))(macroname)) Thanks -- Perry Leets Inovec Optimization and Control Systems Eugene, Oregon
0 Likes
736 Views
13 Replies
Replies (13)
Message 2 of 14

Anonymous
Not applicable
Use (command "VBARUN" ...) instead of "VBALOAD" in your ACADDOC.LSP
0 Likes
Message 3 of 14

Anonymous
Not applicable
Hi Perry, As you would expect there is a collection of loaded programs which can be investigated, but there is no point in going to all that trouble. The VBARUN command and it's variants will load (if necessary) and run the program. The best way to run your VBA macros, is to define lisp functions to run them. Put the lisp programs in your custom menu file, say PERRY.MNL . These functions get loaded when you load the PERRY.MNU, or PERRY.MNS, or PERRY.MNC file as the case may be. A typical example is: (setq sLandToolboxPath (strcat (vl-registry-read "HKEY_LOCAL_MACHINE\\Software\\CADApps\\LandToolbox" "VBA Program Path") "\\" ) ) In this case the program is installed by "Inno Setup" which writes the installation path to the registry. The code above reads the registry and gets the path. You could easily simply hard code a path here. The code below adds the file and macro name to the path and then uses vl-vbarun to run the function. vl-vbarun runs the macro, loading it if necessary. (defun C:CA_DuplicatePointsAbout () (setq sLandToolboxFunction (strcat sLandToolboxPath "CADApps_DuplicatePointsL3.dvb!DuplicatePointsAbout")) (vl-vbarun sLandToolboxFunction) (CADApps_BlankCommandLine sLandToolboxFunction) ) The code below tidies up the command line when you run the macro (defun CADApps_BlankCommandLine (spString) (setq n (strlen spString)) (repeat n(prompt(chr 8))) (repeat n(prompt(chr 32))) (princ) ) The MNU (or MNS) file contains CA_DupPts [ About Duplicate Points]^C^C^CCA_DuplicatePointsAbout; Advantages of this process are that you can: press to repeat the menu command. type the "CA_DuplicatePointsAbout " command at the keyboard. the macro is only loaded if used. the lisp is only loaded if you load the menu. by having the path in the registry it's easy to maintain the system if you wish to make changes to the program location with an installation program.. -- Laurie Comerford CADApps www.cadapps.com.au "perry" wrote in message news:401e9fc7$1_1@newsprd01... > I want to load some VBA routines each time a drawing is opened (without > using an "acad.dvb" file). > I know I can do this in an "acaddoc.lsp" file with a few lines that look > something like this: > > (if (findfile "perry.dvb") > (command "_-vbaload" "perry") > (alert "personal VBA not loaded.") > ) > > The problem with this approach is that upon opening subsequent drawings I > get an alert box stating that the vba module is already loaded. > With autolisp files I can use a line like this: > (defun C:LM () (if (not c:lman)(load "lman"))(c:lman)) > which will fist check if the routine is already loaded, then load and > execute if it is not. So my question is can I do something similiar with > VBA? > Something along the line of: > (if (not VBAPROJECTNAME)(vbaload "VBAPROJECTNAME"))(macroname)) > > Thanks > -- > Perry Leets > Inovec Optimization and Control Systems > Eugene, Oregon > >
0 Likes
Message 4 of 14

Anonymous
Not applicable
Well, that doesnt quite work, it will look for a macro to run, not a project to load. If I give it a macro name it will still fail because the project the macro resides in isnt yet loaded. -- Perry Leets Inovec Optimization and Control Systems Eugene, Oregon "developer" wrote in message news:11175586.1075749530125.JavaMail.jive@jiveforum1.autodesk.com... > Use (command "VBARUN" ...) instead of "VBALOAD" in your ACADDOC.LSP
0 Likes
Message 5 of 14

Anonymous
Not applicable
Sorry, it worked for me because my project is named ACAD.DVB
0 Likes
Message 6 of 14

Anonymous
Not applicable
Yeah, I was trying to get away from using the "acad.dvb" (easy to loose/overwrite), but I may have to -- Perry Leets Inovec Optimization and Control Systems Eugene, Oregon "developer" wrote in message news:13322849.1075757844835.JavaMail.javamailuser@localhost... > Sorry, it worked for me because my project is named ACAD.DVB
0 Likes
Message 7 of 14

Anonymous
Not applicable
Hey Perry, check out AutoCAD's online help for the VBARUN command. I think you can still use that command to achieve what you want.
0 Likes
Message 8 of 14

Anonymous
Not applicable
My ACADDOC.LSP has the following line in S::STARTUP

(command "VBARUN" "L:\\CAD\\VBA\\ACAD.DVB!DwgMod.DwgStartup")

You can use the full path to your project, the bang (exclamation point), the module name, and the macro name. I assure you the project will load if it is not loaded.
0 Likes
Message 9 of 14

Anonymous
Not applicable
Yes, I did see that and it is another alternative, I was avoiding it for reasons similar to the acad.dvb issues. Its easy to overwrite or mess up the acaddoc/s::startup routines. I guess I'll just settle on using an acad.dvb file. Thanks for the tips D ;) -- Perry Leets Inovec Optimization and Control Systems Eugene, Oregon "developer" wrote in message news:2609622.1075760048916.JavaMail.jive@jiveforum1.autodesk.com... > My ACADDOC.LSP has the following line in S::STARTUP > > (command "VBARUN" "L:\\CAD\\VBA\\ACAD.DVB!DwgMod.DwgStartup") > > You can use the full path to your project, the bang (exclamation point), the module name, and the macro name. I assure you the project will load if it is not loaded.
0 Likes
Message 10 of 14

Anonymous
Not applicable
Well, Im not real happy with any of these methods. My first method worked with the one exception I mentioned. Using an acad.dvb file, I dont even know if it actually loads as the code doesnt execute. To clarify, this is a small vb project which simply "hooks" the endsave event and creates a .dwf file of the current .dwg. If an "acad.dvb" file exists, must you do something else to initialize the VB environment? What would be really helpful would be a way to determine if a particular vba project or macro is loaded, then I could test for this in my inital code snippent and not issue the "vbaload" if its already loaded. This is all so ridiculously easy with lisp... -- Perry Leets Inovec Optimization and Control Systems Eugene, Oregon
0 Likes
Message 11 of 14

Anonymous
Not applicable
I imagine you already know this, but just in case, do you have an acad.rx file in support path? with one of the following lines acadvba.arx ;(if 2002) ;acvba.arx ;(if 2004) that initializes vba before any macros run "perry" wrote in message news:401ed762$1_1@newsprd01... > Well, Im not real happy with any of these methods. My first method worked > with the one exception I mentioned. > Using an acad.dvb file, I dont even know if it actually loads as the code > doesnt execute. > To clarify, this is a small vb project which simply "hooks" the endsave > event and creates a .dwf file of the current .dwg. > If an "acad.dvb" file exists, must you do something else to initialize the > VB environment? > What would be really helpful would be a way to determine if a particular vba > project or macro is loaded, then I could test for this > in my inital code snippent and not issue the "vbaload" if its already > loaded. > This is all so ridiculously easy with lisp... > > -- > Perry Leets > Inovec Optimization and Control Systems > Eugene, Oregon > >
0 Likes
Message 12 of 14

Anonymous
Not applicable
Yeah, I was just about to make a post on that Mark. My "acad.dvb" file wasnt working cuz I didnt have an "acad.rx" file, so I created said file containing just one line "acadvba.arx", now the code in my acad.dvb DOES load and execute properly (hooking the save event). I guess if I wanted to distribute this my setup program would have to check for the existance of both an acad.dvb and acad.rx file and create/modify them accordingly. Thanks -- Perry Leets Inovec Optimization and Control Systems Eugene, Oregon "Mark Propst" wrote in message news:401ee054_3@newsprd01... > I imagine you already know this, but just in case, do you have an acad.rx > file in support path? > with one of the following lines > acadvba.arx ;(if 2002) > ;acvba.arx ;(if 2004) > > that initializes vba before any macros run
0 Likes
Message 13 of 14

Anonymous
Not applicable
Glad ya got it! :-)~ plus you'd have to check acadver if you were writing an .rx in a setup routine to determine which line to put in it! and if they have both installed on same machine you'd have to get support path for each one and write two .rx's, one for each path, (unless there's a way to write an if statement in the rx to read acadver...I have no idea how .rx is actually read and if you can include a conditional loop in it) "perry" wrote in message news:401ee173$1_1@newsprd01... > Yeah, I was just about to make a post on that Mark.
0 Likes
Message 14 of 14

Anonymous
Not applicable
Search the lisp discussion group for a thread "DVB file already loaded" dated Jan/30/02 by Menzi, Jürg He has a lisp function to return a list of all loaded dvb projects so you can use (if (not (member "MyVbaProjectName" (VxGetLoadedVbaPojs))) (vl-vbaload "MyVbaProjectName.dvb") )
0 Likes