AfraLisp Blog

The AutoLisp/Visual Lisp/VBA Resource Website

AfraLisp Blog

Home Newsletter Utter Rubbish Coding Tips AutoCAD Tips Contact Downloads WAUN

Loading VBA Projects

When you load an AutoLisp file you just type (load "MYLISPFILE") and AutoCAD will find the file and load it, as long as it is located within the AutoCAD search path.
Loading a VBA Project file though, is slightly different. AutoCAD will only search the current working directory for the VBA file. The way to get around this, and to force AutoCAD into searching the AutoCAD search path, is to use the "Findfile" function.
The following AutoLisp coding will load any VBA Project file that is within the AutoCAD search path, run the Project and then unload it on completion.
Thanks to Randall Rath of VBDesign for this idea.

(defun c:ldvb ()
;define function

	(setvar "CMDECHO" 0)
	;switch off command echo

	(if (findfile "yourproject.dvb")
	;if the project file is found
	;in your AutoCAD search path

	   (progn
	   ;do the following

		(setvar "FILEDIA" 0)
		;switch off dialogue boxes

		(command "_vbaload" 
		(findfile "yourproject.dvb"))
		;load the project file

		(command "-vbarun" "yourprojectmacro")
		;run the project macro

		(command "_vbaunload")
		;unload the file

		(setvar "FILEDIA" 1)
		;switch dialogues back on

	  );progn

	  (princ "\nyourproject.dvb not found")
	  ;if project not found, inform the user

	);if

	(setvar "CMDECHO" 1)
	;switch command echo back on

   (princ)
   ;finish clean

);defun

(princ "\nyourproject.dvb Loaded")
;inform user

(princ "\nType 'Ldvb' to Run")
;tell him how to run it

(princ)
;load clean
 
The AutoLisp/Visual Lisp/VBA Resource Website

Copyright © 1999-Perpetuity by AfraLisp

All rights reserved.
Information in this document is subject to change without notice.
Site created and maintained by Kenny Ramage

The AutoLisp/Visual Lisp/VBA Resource Website