Here is an example:
(defun c:fun1()
...do something...
(sub01)
...do something else...
); end of c:fun1
(defun c:fun2()
...do something...
(sub01)
...do something else...
); end of c:fun2
(defun sub01()
... do whatever...
); end lf sub01
Once the file containing the sub01 definition is loaded then any routine can
call that function.
Good lisping,
Mike Weaver
Matthew Dwyer wrote in message <6h33fn$q6...@adesknews2.autodesk.com>...
Here's one way.
fl.lsp is defined externally,
Variables vue, ip, name and data are set in the main program.
flx; where x= s, l, 3 are subroutines contained within fl.lsp
John
(defun fl (vue )
(assert "\n Entered fl. ")
(load "fl")
(cond
((= vue "S")(fls ip name data ))
((= vue "L")(fll ip name data ))
((= vue "R")(fll ip name data ))
((= vue "T")(fls ip name data ))
((= vue "O")(fls ip name data ))
((= vue "B")(fls ip name data ))
((or (= vue "3")(= vue "3D"))(fl3 ip name data ))
(T (princ "\n Fell through fl."))
)
(princ)
)
(c:foo)
--
/*********************************************************/
/* Tony Tanzillo Design Automation Consulting */
/* Programming & Customization for AutoCAD & Compatibles */
/* ----------------------------------------------------- */
/* Member of the OpenDWG Alliance */
/* Co-Author of Maximizing AutoCAD R13 and */
/* Maximizing AutoLISP for AutoCAD R13/R14 */
/* ----------------------------------------------------- */
/* tony.t...@worldnet.att.net */
/* http://ourworld.compuserve.com/homepages/tonyt */
/*********************************************************/
Matthew Dwyer wrote in message <6h33fn$q6...@adesknews2.autodesk.com>...
Matthew Dwyer wrote in message <6h33fn$q6...@adesknews2.autodesk.com>...
>I know it is possible to use a lisp program to load another EXTERNAL lisp
>program. But how do i invoke the called program without physically using
>the keyboard. (I have a part insertion program and need to call an
external
>"tweak" lisp program for part modification purposes.) I don't see the
point
>in copying the "tweak" code to each insertion routine because if I need to
>change something, all routines will have to be altered. Info?
>
>
You're right, there's no need to "tweak" code for each insertion routine
when you can use autoload in your acad. Look at approx. line# 315 in your
acadr14.lsp file, should be in your support directory:
;;;===== AutoLoad LISP Applications =====
; Set help for those apps with a command line interface
(autoload "appload" '("appload" "appload"))
(autoload "edge" '("edge"))
(setfunhelp "C:edge" "" "edge")
(autoload "filter" '("filter " "filter"))
(autoload "3d" '("3d" "3d" "ai_box" "ai_pyramid" "ai_wedge" "ai_dome"
"ai_mesh" "ai_sphere" "ai_cone" "ai_torus" "ai_dish")
)
;;>>>>>>>>>>>>>>>>>>>>>>>>>>>
(autoload "your-code" '("your-code"))
;;<<<<<<<<<<<<<<<<<<<<<<<<<<<
Note: I may be wrong, but I think you have to reference functions defined
as
c:function-name, i.e. plain old function-name won't work.
Another way to do it follows. It's not really 'demand loading', but that's
what
I named it so I can find the file later ( if I manage to rememer composing
it).
Maybe this example code (meant to be placed in two separate files) will
help:
NOTE: Be sure to change the "path" variable to match the directory you place
the code in.
;;--------------------------------------------
;; Example of demand loading.lsp
;;--------------------------------------------
;;
;; link...@sprintmail.com 4/15/98
;;
;;--------------------------------------------------------------------------
----
;; Put the following code in a file called 'print message.lsp'.
;;--------------------------------------------------------------------------
----
;; Load it into Acad and type 'print-message' at the command line.
(defun c:print-message ()
;; Set up a path string (you'll need to change this depending on
;; where you put you AutoLISP files).
(setq path "c:/your lisp directory/")
;; Disallow null input, define keyword options.
(initget 1 "Yes No Maybe")
;; Get keyword, i.e. type the first letter, upper
;; or lower case, of any of the available keywords.
(setq keyword (getkword "Yes/No/Maybe?: "))
;; Depending on the keyword, execute the associated function.
;; If either :yes, :no, or :maybe are nil, load the file
;; "yes no maybe.lsp", making all three functions available
;; to you program without requiring you to touch the keyboard.
;; With large apps you may want to load-on-demand one at a time
;; instead a several at once as in the example.
(cond
((= keyword "Yes")
(if (not :yes)(load (strcat path "yes no maybe.lsp")))
(:yes)
)
((= keyword "No")
(if (not :no)(load (strcat path "yes no maybe.lsp")))
(:no)
)
((= keyword "Maybe")
(if (not :maybe)(load (strcat path "yes no maybe.lsp")))
(:maybe)
)
)
)
;;-------------------------------------------------------------------
;; Put this code in a file called "yes no maybe.lsp".
;;-------------------------------------------------------------------
;; Yes No Maybe.lsp
(defun :yes () (alert "Yes"))
(defun :no () (alert "No"))
(defun :maybe () (alert "Maybe"))