samifox Posted July 12, 2017 Posted July 12, 2017 hi i have tons of lisps , but i want to load them on demand, so in every button ill have this little macro script (defun isLoaded) (if(not (loaded script)) (load lisp) ) ) need some help with the syntax Quote
rlx Posted July 12, 2017 Posted July 12, 2017 http://www.cadtutor.net/forum/showthread.php?83897-Combining-Lisp-routines Quote
samifox Posted July 12, 2017 Author Posted July 12, 2017 http://www.cadtutor.net/forum/showthread.php?83897-Combining-Lisp-routines quoted from the psot you post (defun c:yc () (if (not c:ycopy) (load "YCOPY"))(c:ycopy)) if c:copy dont returns "unknowen command" than load it, how it works? Quote
BIGAL Posted July 12, 2017 Posted July 12, 2017 Look into help "not" it is just does not exist so like a normal IF do the next statement or else (defun c:yc () (if (not c:ycopy) (load "YCOPY")(princ "\nlisp Loaded"))(c:ycopy)))) Calling a library defun needs to be loaded in middle of code. (if (not AH:getval2) (load "getvals")) (ah:getval2 "Enter start tab number" 6 4 "Enter end tab number" 6 4) Quote
samifox Posted July 12, 2017 Author Posted July 12, 2017 Look into help "not" it is just does not exist so like a normal IF do the next statement or else (defun c:yc () (if (not c:ycopy) (load "YCOPY")(princ "\nlisp Loaded"))(c:ycopy)))) when typing a command that not exist the prompt "Unknown command" prints, so is that considered as nill? Quote
rlx Posted July 12, 2017 Posted July 12, 2017 in my toolbar I use ID_VT [_Button("VT", "C:/TEMP/LISP/BMP/VT.bmp", "ICON_16_BLANK")]^C^C(IF (NOT c:vt)(LOAD"VT.LSP") );VT else you can also look into atoms-family to see if your routine is part of the current family (= is loaded) gr.Rlx Quote
Tharwat Posted July 12, 2017 Posted July 12, 2017 Besides that, the findfile function must be side by side with load function to avoid the error message and failure if lisp file not found. Quote
samifox Posted July 12, 2017 Author Posted July 12, 2017 Besides that, the findfile function must be side by side with load function to avoid the error message and failure if lisp file not found. can you provide en example? Quote
BIGAL Posted July 12, 2017 Posted July 12, 2017 Tharwat has offered a good idea using findfile but if your going to dynamically load it would be far better to spend a few minutes setting directory paths of where your code is being saved and have some consistency or standards rather than randomly saving code any where on your hard disk. You can also hard code the the Load with a full path. On a commercial product we had a install routine so we knew where the files were being saved to on a users hard disk. You can do the same with lisp copy files and set the support paths. Quote
CadJunky Posted July 12, 2017 Posted July 12, 2017 I just use the following and place into my Acaddoc.lsp file. (autoload "BatchPurge" '("BatchPurge")) (autoload "GetX" '("GetX")) (autoload "RTB" '("RTB")) Quote
Steven P Posted July 12, 2017 Posted July 12, 2017 (edited) I tend to keep all my LSP files in the same location and if I don't load them at start up have a command to load them all at once. For the few I have and their size, this takes very little time. Also useful when developing a lisp, I can reload it from the command line: (defun c:appreload () (setq mydir "C:\\AutoCAD LISPS\\") ;;Location of LSP files. If more than 1 location can do subroutine and change mydir location (setq myfiles (vl-directory-files mydir "*.lsp" nil)) ;;myfiles is list of files in mydir location (setq mylistlength (length myfiles)) ;;count of number of lsp files (setq acount -1) (repeat mylistlength (setq acount (1+ acount)) (load (strcat mydir (nth acount myfiles))) ;;loads lsp files from folder 1 at a time ) (princ "\n") (princ mylistlength) (princ " lsp files loaded from ") (princ mydir) (princ) ) OK the code could be tidied up but it works Edited July 13, 2017 by SLW210 Fix Code Tag Quote
BIGAL Posted July 13, 2017 Posted July 13, 2017 Re unkown command, you can trap the error and look at what the command was and then say load a lisp and rerun, problem is how many error trap reactors do you want. I use the error to set my fillet command shorthanding the Fillet R 100 to f100 same with offset and circle can enter any value after the initial character. I guess you if you make every custom command sm.... it would work as you could check the error and maybe load a lisp Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.