TheSwamp

Code Red => AutoLISP (Vanilla / Visual) => Topic started by: DanB on July 31, 2018, 08:25:14 AM

Title: Combine multiple lisp routines?
Post by: DanB on July 31, 2018, 08:25:14 AM
I'm putting together a custom ribbon to share with co-workers. My first run through has about 10 custom commands. Customization will be stored on the server. I've compiled the individual routines into *.fas files. Is it possible to go a step further and combine all the routines into a single file? Recommended?
Title: Re: Combine multiple lisp routines?
Post by: ChrisCarlson on July 31, 2018, 08:52:05 AM
Just combine all of the files into a single lisp file and then compile.
Title: Re: Combine multiple lisp routines?
Post by: tombu on July 31, 2018, 09:11:28 AM
I use a different approach.  My ribbon calls many custom lisp commands.  I don't preload the lisp for any of them.  Using either the autoload (AutoLISP) function or the acet-autoload2 (Express Tool) function allows your users to enter the command name of a lisp routine and have it automatically load if it hasn't already been loaded and run without preloading any of them.  Much easier to avoid or find conflicts with lisp routines when they're loaded as needed.  What happens when one of them doesn't work as expected with your next upgrade?

Most of my lisp is run from the ribbon so I'll use a macro like:
Code: [Select]
^P(or C:Rotoggle (load "Rotoggle.lsp"));Rotoggle which loads the lisp only if it's not already loaded, then runs the command.  As this particular macro toggles text rotation between horizontal and 0 I put it in the Shortcut for Text & Mtext Object & Objects Menus.  Putting most modify commands for specific object types in the Shortcut Menus simplifies the ribbon.  Our custom CUI has two Tabs with many Panels and I keep it trimmed down as best I can.
Title: Re: Combine multiple lisp routines?
Post by: DanB on July 31, 2018, 09:29:59 AM
Just combine all of the files into a single lisp file and then compile.

That goes back to my question, is this simply cut-n-paste from each routine into a single *.lsp or is there an additional process available (i.e. in VLIDE)?

tombu - I like that macro, thanks.
Title: Re: Combine multiple lisp routines?
Post by: dgorsman on July 31, 2018, 09:59:50 AM
While it's easier to load a single file, if things start getting complicated it can be a bit of a bother trying to track down something in a 10k+ line file.  If you have more than a few files, create a loader routine (in it's own file 'cause you know - organization  :-P ) to handle the rest.

And whatever you do, don't lose track of the source code.
Title: Re: Combine multiple lisp routines?
Post by: cmwade77 on July 31, 2018, 12:53:36 PM
It depends on how large they are, it used to be that I would put all LISP routines into a few files, but the problem is that when loaded this can become a drain on memory. So I divided them out and used an autoload routine so they only load when someone uses the command.

Now mind you I made this change many years ago when computers were much more limited on RAM than they are now, but I find it still is a good practice and keep the same technique going. It also makes editing LISP routines much easier down the road.
Title: Re: Combine multiple lisp routines?
Post by: DanB on July 31, 2018, 01:09:27 PM
Thanks for all the feedback. Think I am going to keep as individual files and incorporate the demand loading.
Title: Re: Combine multiple lisp routines?
Post by: Crank on July 31, 2018, 01:24:10 PM
Another approach:
Code - Auto/Visual Lisp: [Select]
  1. (defun c:LOADALL (/ LispPath LispList n)
  2.         (setq LispPath "I:/Acad2019/Programs/")
  3.         (setq LispList (vl-directory-files LispPath "*.fas" 1))
  4.         (foreach n LispList
  5.                 (load (strcat LispPath n))
  6.         )
  7.         (princ "\nALL .FAS-FILES LOADED.\n")
  8. )
Title: Re: Combine multiple lisp routines?
Post by: MSTG007 on July 31, 2018, 01:35:13 PM
That's kinda what I do. I have a whole folder with subfolders of each commands. Then I can void out the older lisp and still keep it with the original if I ever need to go back. Works well. I also call the routine on demand. its not preloaded.
Title: Re: Combine multiple lisp routines?
Post by: DanB on July 31, 2018, 02:58:55 PM
Keeps getting better, thanks for that one too Crank.
Title: Re: Combine multiple lisp routines?
Post by: VovKa on July 31, 2018, 04:29:11 PM
(i.e. in VLIDE)?
good idea

run vlide
create a project
add all your lisps to it
check toggle 'Single module for all'
build project fas