Jump to content

load lisp if its not already loaded


samifox

Recommended Posts

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 :)

Link to comment
Share on other sites

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)

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

I just use the following and place into my Acaddoc.lsp file.

 

(autoload "BatchPurge" '("BatchPurge"))
(autoload "GetX" '("GetX"))
(autoload "RTB" '("RTB"))

Link to comment
Share on other sites

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 by SLW210
Fix Code Tag
Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...