Author Topic: ACADDOC.lsp - Loading inter-dependent files with command call.  (Read 2680 times)

0 Members and 1 Guest are viewing this topic.

Cuddles

  • Guest
ACADDOC.lsp - Loading inter-dependent files with command call.
« on: January 28, 2015, 04:03:54 PM »
Hello Everyone,

I'm having an issue auto-loading multiple LISP files which are interdependent.

The program is called "Inertia" which, obviously, calculates various properties for selected sections.

There are 3 files in total: "INERTIA", "INERTIA1" & "INERTIA2". All 3 files must be loaded for the function to operate. The command call is simply "inertia".

The 3 files cannot be combined into one as one of the files is protected (INERTIA2), a real pain.

So, in my ACADDOC.lsp file, how do I go about loading (or auto-loading) these 3 files when I issue the command call at the command line.

An example call (which doesn't work):
Code: [Select]
(autoload "INERTIA" "INERTIA1" "INERTIA2" '("inertia"))
I would prefer not to have the files load on opening AutoCAD or a drawing (prefer autoload).

All advice and comments are welcome.

Thanks,
Cuddles

ronjonp

  • Needs a day job
  • Posts: 7535
Re: ACADDOC.lsp - Loading inter-dependent files with command call.
« Reply #1 on: January 28, 2015, 04:19:59 PM »
Look into the LOAD function.

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

BlackBox

  • King Gator
  • Posts: 3770
Re: ACADDOC.lsp - Loading inter-dependent files with command call.
« Reply #2 on: January 28, 2015, 05:13:14 PM »
Another option to loading all three into memory up front, is to Autoload the main file, and modify that to first check for each of the three dependent files, testing for either defined global variable (or function?) representing each.

That way, you still benefit from demand-loading, and minimize the overhead of loading the routine's dependencies.

Pseudo code:
Code - Auto/Visual Lisp: [Select]
  1. (defun c:FOO ()
  2.  
  3.   ;; demand load
  4.   (if (not INERTIA) (load "INERTIA.lsp" "nope"))
  5.   (if (not INERTIA1) (load "INERTIA1.lsp" "nada"))
  6.   (if (not INERTIA2) (load "INERTIA2.lsp" "not going to happen"))
  7.  
  8.   ;; main code
  9.   (if (and INERTIA INERTIA1 INERTIA2)
  10.     (progn
  11.      ;;<-- do something useful
  12.     )
  13.     (prompt "\n** One or more dependent files cannot be found ** ")
  14.   )
  15.   (princ)
  16. )
  17.  
"How we think determines what we do, and what we do determines what we get."

Lee Mac

  • Seagull
  • Posts: 12937
  • London, England
Re: ACADDOC.lsp - Loading inter-dependent files with command call.
« Reply #3 on: January 28, 2015, 05:55:13 PM »
Similar to BlackBox's suggestion above, you could roll your own multi-file autoload, e.g.:

Code - Auto/Visual Lisp: [Select]
  1. (defun inertiaload ( cmd lst / sym )
  2.     (if (not (eval (setq sym (read (strcat "c:" cmd)))))
  3.         (eval
  4.             (list 'defun sym '( / def tmp )
  5.                 (list 'setq 'def sym)
  6.                 (list 'if (list 'vl-every ''(lambda ( lsp ) (/= 'loadfailed (load lsp 'loadfailed))) (list 'quote lst))
  7.                     (list 'if (list 'eq 'def sym)
  8.                         (list 'princ (list 'strcat "\nThe command \"" cmd "\" could not be redefined."))
  9.                         (list sym)
  10.                     )
  11.                    '(princ "\nOne or more program files could not be loaded.")
  12.                 )
  13.                '(princ)
  14.             )
  15.         )
  16.     )
  17.     (princ)
  18. )

Code - Auto/Visual Lisp: [Select]
  1. (inertiaload "inertia" '("inertia.lsp" "inertia1.lsp" "inertia2.lsp"))

Cuddles

  • Guest
Re: ACADDOC.lsp - Loading inter-dependent files with command call.
« Reply #4 on: February 04, 2015, 09:55:17 PM »
Hey Guys,

Thanks for the suggestions - appreciated.

Unfortunately, i haven't yet tried them out but will report back if any issues arise.

Thanks again,
Cuddles.

tombu

  • Bull Frog
  • Posts: 289
  • ByLayer=>Not0
Re: ACADDOC.lsp - Loading inter-dependent files with command call.
« Reply #5 on: February 05, 2015, 08:20:19 AM »
One more option.  Since only INERTIA2 is protected you could add a test for a command in INERTIA2 that loads the INERTIA2 if it isn't found into INERTIA.  Then add another for INERTIA1.  Something like:
Code: [Select]
(or INERTIA2 (load "INERTIA2.lsp"))Now all you need to do is autoload INERTIA.  If you didn't want to modify INERTIA you could add INERTIA_load.lsp just to load the other 3 files and autoload it with the command call "inertia".
Tom Beauford P.S.M.
Leon County FL Public Works - Windows 7 64 bit AutoCAD Civil 3D