Best way to load many lisps

Best way to load many lisps

johnw
Collaborator Collaborator
5,078 Views
13 Replies
Message 1 of 14

Best way to load many lisps

johnw
Collaborator
Collaborator

I'm old school and have my acad. lsp file load some lisp routines for me. The biggest file called "loadlisps" contains a long list of small routines and also another long list of code lines to "load lisp files" from other locations. e.g. (load "C:/lisp/doorway") (load "C:/lisp/windowop") and on and on and on.

 

I want to make my lisp routine loading more efficient if possible and I also would like to put all my code in one file and then compile that information to a .fas file so no one can see my code.

 

Does anyone have ideas as to the best way/place to store and to quickly load my files, and the best way to get all of them into ONE file? Or articles that would show me the best up-to-date ways of doing this?

 

Thanks,

 

John

0 Likes
5,079 Views
13 Replies
Replies (13)
Message 2 of 14

rkmcswain
Mentor
Mentor

You should be loading them using “acaddoc.lsp”, since by default “acad.lsp” only loads once at application startup.

 

Generally speaking, the concept of making your code load more efficiently and putting all of the code in one file conflict each other.

 

One thought to make the loading more efficient is to use (autoload). This way the actual code doesn’t load until you need it.

 

As far as combining all your code into one file, that is pretty straightforward. Just copy and paste all your code into one file. Doing that will increase the load time of that one file, but even so, we’re only talking about a second or two. If you make a .FAS file, just be sure to keep the source (.LSP) files in a safe place. The same security that keeps others out of your code (by using .FAS) will also keep you out of it.

R.K. McSwain     | CADpanacea | on twitter
Message 3 of 14

Anonymous
Not applicable

autoloading is the way to go, i use it on most of mine with a full file path as below.

 

(autoload "C:yourfilepath/yourlisp.lsp" '("yourlispcommand-a" "yourlispcommand-b"))

0 Likes
Message 4 of 14

dgorsman
Consultant
Consultant

Auto-loading is fine if everything is defined as command functions.  A lot of our LISP files are library functions, so instead of an auto-loader I have a custom loading function which parses loadable files from a folder then attempts to load each one (with error handling, of course).

----------------------------------
If you are going to fly by the seat of your pants, expect friction burns.
"I don't know" is the beginning of knowledge, not the end.


0 Likes
Message 5 of 14

Anonymous
Not applicable
Cant you just load the function when the lisp you call runs?
0 Likes
Message 6 of 14

Shneuph
Collaborator
Collaborator

This is how I've been loading (inside the acaddoc.lsp file).  All my lisp files are in 2 folders.  1 folder for functions that are always loaded and 1 for commands that are demandloaded.  This way if I write or come across a new lisp that I want to keep, all I have to do is save it in the appropriate folder and it becomes available.  A lot of the code is fluff for commandline reporting... but you can dissect it.

 

If anyone wants to make recommendations for improvement I'm all ears.

 

;Autoload Functions
(terpri)
(princ "\n===== Autoloading Custom Functions ===========")
(Setq TLV-LineLength 1)
;;;THIS AUTOLOAD FUNCTION WILL LOAD ANY LISP INSIDE THE SPECIFIED FOLDER INTO YOUR
;;;CURRENT AUTOCAD SESSION.  FUNCTIONS THAT WILL BE USED IN OTHER LISP SHOULD BE
;;;AUTOLOADED.
(foreach x (vl-directory-files "T:\\CAD Support\\LISP\\AutoLoad" "*.lsp")
  (if (> (strlen x) TLV-LineLength)
    (Setq TLV-LineLength (strlen x))
    );if
  );foreach
(Setq TLV-LineLength (- TLV-LineLength 5))
(terpri)
(foreach x (vl-directory-files "T:\\CAD Support\\LISP\\AutoLoad" "*.lsp")
  (Setq TLV-DashString "-")
  (repeat (- TLV-LineLength (strlen x))
    (Setq TLV-DashString (strcat TLV-DashString "-"))
    );repeat
  (princ (Strcat "Loading " (strcase x) ": "))
  (setq TLV-LoadReturn (load (strcat "T:\\CAD Support\\LISP\\AutoLoad\\" x) "Fail!"))
  (cond
    (
     (= TLV-LoadReturn nil)
     (if (> (strlen (strcat "Loading " x ": " TLV-DashString " LOAD FAILED!!")) 80)
       (progn
	 (terpri)
	 (princ "                                                    ---------- LOAD FAILED!!")
	 );progn
       (princ (strcat TLV-DashString " LOAD FAILED!!"))
       );if
     );cond1
    (;cond2
     (= TLV-LoadReturn "Fail!")
     (princ (strcat x "FAILED - File not found!"))
     );cond2
    (;cond3
     TLV-LoadReturn
     (princ tlv-dashstring)
     (princ TLV-LoadReturn)
     );cond3
    );cond
  (terpri)
  );foreach


;===============================================================================
;Auto Demandload Commands
(terpri)
(princ "\n===== Demand-loading Custom Commands =========")
;;;THIS DEMANDLOAD FUNCTION WILL DEMANDLOAD ANY LISP INSIDE THE SPECIFIED FOLDER
;;;INTO YOUR CURRENT AUTOCAD SESSION.  COMMAND LISPS CAN BE DEMAND LOADED SO THAT
;;;THE ONLY LOAD WHEN THEY ARE USED. !!!DEMAND LOAD FILE NAMES MUST MATCH THE
;;;DEMAND LOAD COMMAND NAME!!!
;;;i.e. "C:Drawabunchoflines" goes in "Drawabunchoflines.lsp"
(foreach x (vl-directory-files "T:\\CAD Support\\LISP\\DemandLoad" "*.lsp")
  (if (not (autoload x (list x)))
    (princ (strcat "\nDemand-Loading: " x))
    );if
  );foreach
(terpri)
(princ "\n* Demand-Loaded Commands will be loaded on first use.")
(terpri)

acaddocreport.jpg

 

Can't help with the .fas file.  I have no experience with those.

---sig---------------------------------------
'(83 104 110 101 117 112 104 64 71 109 97 105 108 46 99 111 109)
0 Likes
Message 7 of 14

scot-65
Advisor
Advisor
>>>Cant you just load the function when the lisp you call runs?

Autoload does just that.

Another method which bypasses the command-line noise of Autoload is as follows:

(defun c:ABC () (load "MyABCroutine")(c:ABC)(princ)) ;brief description goes here
(defun c:BCD () (load "AnotherBCDroutine")(c:BCD)(princ)) ;another brief description
...
(princ "MyMenuSystem Master Utility loaded. ")

Populate a file with each line as shown above and name that file "Master_Utility.lsp"
or similar. Each line will represent one stand-alone routine.

The catch here is this will demand load upon the first call where both "c:ABC" MUST
BE PRESENT, so when the routine loads, the keystroke is redefined.

Next step is to create a folder to place all these stand-alone routines. I might add
debugging is easier when separate files, especially large routines (greater than
10 lines of code).

Now the easy part:
For each new routine one develops (or acquires), place file in folder and add another
line of code to the Master_Utility file. That's it.

Shneuph gives a good hint as well. For "Menu Functions", places these blocks of
code in a single file and name this file the same name as the CUIX but with the
extension being MNL. As long as the CUIX is used, the MNL will load.

Example: MyMenu.CUIX and MyMenu.MNL

As well as menu functions inside the MNL, one can also load the Master_Utility from here.

In one of my menu systems I have 87 stand-alone routines that load using this geometry
(the other one has 169)... and growing.

???

Scot-65
A gift of extraordinary Common Sense does not require an Acronym Suffix to be added to my given name.

0 Likes
Message 8 of 14

stevor
Collaborator
Collaborator

May have been answered by now,

but,  for non command lisp loading,

what was used was to check for the existence

of one of the definition or variable names:

 (if (not MyLibLspFunction)) ; the function or variable name

  (load "MyLibLsp") ; the file

 )

May have to add the path.

S
0 Likes
Message 9 of 14

martti.halminen
Collaborator
Collaborator

@Anonymous wrote:

I'm old school and have my acad. lsp file load some lisp routines for me. The biggest file called "loadlisps" contains a long list of small routines and also another long list of code lines to "load lisp files" from other locations. e.g. (load "C:/lisp/doorway") (load "C:/lisp/windowop") and on and on and on.

 

I want to make my lisp routine loading more efficient if possible and I also would like to put all my code in one file and then compile that information to a .fas file so no one can see my code.

 

Does anyone have ideas as to the best way/place to store and to quickly load my files, and the best way to get all of them into ONE file? Or articles that would show me the best up-to-date ways of doing this?

 

If your routines are not mutually incompatible, why not compile the whole thing into a .VLX file?

 

http://help.autodesk.com/view/ACD/2015/ENU/?guid=GUID-1412948C-762E-43D9-8F38-CF58B17ADD73

 

 

- We are loading a .vlx file created from 63 .lsp files, containing about 1800 defuns, in our acaddoc.lsp, taking about 0.3 seconds to load.

 

- Given that kind of speed, I see no need to fiddle with autoloading.

 

-- 

 

 

-- 

 

0 Likes
Message 10 of 14

johnw
Collaborator
Collaborator
Thank you all for the ideas and information provided! I appreciate all the comments and suggestions!

John
0 Likes
Message 11 of 14

johnw
Collaborator
Collaborator

I've taken all my lisp routines and cut and pasted them into a acaddoc.lsp file. file is loaded without errors when opening autocad.

 

I then compiled the file into a .fas file and durring the compiling i received "warnings", but the compiler said it was successful. I've attached the warnings so you can see. I don't know which routines these warnings are about so it will be difficult to pin-point the issues if there really are any.

 

Do these warnings mean some routine or routines within the file aren't going to work properly?

0 Likes
Message 12 of 14

martti.halminen
Collaborator
Collaborator

@Anonymous wrote:

I've taken all my lisp routines and cut and pasted them into a acaddoc.lsp file. file is loaded without errors when opening autocad.

 

I then compiled the file into a .fas file and durring the compiling i received "warnings", but the compiler said it was successful. I've attached the warnings so you can see. I don't know which routines these warnings are about so it will be difficult to pin-point the issues if there really are any.

 

Do these warnings mean some routine or routines within the file aren't going to work properly?


First, it would be architecturally cleaner if you built the system in some other file, only loading it by a call in acaddoc.lsp (when it is finished, not during debugging).

 

Compiler saying it was successful only means it didn't crash. I'm pretty sure the end result won't do what you intended.

 

All of those warnings look like either the program is trying to do really crazy things, or the cutting and pasting managed to mix up the program structure pretty badly.

 

Probably easiest to scrap the whole thing and try again.

- If you continue with this cut-and-paste idea, start with just one file, and if it compiles, add the contents of another and compile again. In that case you have a much smaller amount of code to try to find the bugs in, instead of everything at once.

 

- I think it would be better to just list the file names in a project file and let the compiler handle the cutting and pasting.

 

Try reading http://help.autodesk.com/view/ACD/2015/ENU/?guid=GUID-3498C7B4-DC0D-4F3B-AE8E-436AE6E3F104 and the things it is linked to.

 

-- 

 

0 Likes
Message 13 of 14

johnw
Collaborator
Collaborator

I took a few hours to load each routine (that worked individually) into this file. Painstakingly making sure I copy pasted all the code. every has been working and I went back to see if I could pin point which routine was giving "warnings" during the compiling process.I found one of them, and went and tested that routine inside autocad and it still worked fine.

 

There is one routine that I cannot compile and it says there's a fatal error and cannot compile. But I've been running that command for many years and it works fine. I try to add that one to the acaddoc.lsp and then the acaddoc.lsp file doesnt load until I remove it. Very odd for sure.

 

So i removed the one that didn't work and left the remaining as is and all seems to be working good.

 

One thing I noticed is that if the acaddoc file loads or doesn't load there is no notification so I had to add a (prompt "file successfully loaded") at the end of it so I could see if there was a problem or not.

 

Thanks for everyone's input with this!

0 Likes
Message 14 of 14

rkmcswain
Mentor
Mentor
johnw wrote:

One thing I noticed is that if the acaddoc file loads or doesn't load there is no notification so I had to add a (prompt "file successfully loaded") at the end of it so I could see if there was a problem or not.

The solution you discovered is pretty much SOP for most of us. I have a similar line at the end of all my startup files so I can watch a drawing load and visually see that everything is loading.
R.K. McSwain     | CADpanacea | on twitter
0 Likes