Making a function run when a lisp code is loaded with appload

Making a function run when a lisp code is loaded with appload

Anonymous
Not applicable
1,913 Views
3 Replies
Message 1 of 4

Making a function run when a lisp code is loaded with appload

Anonymous
Not applicable

What I'm trying to do is pretty simple, I have a routine and I want that, when someone loads it into autocad, a pop up appears on the screen with a little explaining of what it does. I know how to do the popup, but I have no idea on how to make it run specifically when the routine is loaded, any suggestions ?

0 Likes
Accepted solutions (1)
1,914 Views
3 Replies
Replies (3)
Message 2 of 4

kajanthangavel
Advocate
Advocate
Accepted solution
(<< Your lisp Code >>)
(alert "Lisp Load Successfully")
Message 3 of 4

john.uhden
Mentor
Mentor

It's all about the LSP file you load.  It should be structured something like this:

(vl-load-com)
;; Define any global functions you want to use
(defun function1 (local1 local2)
   ;; blah blah
)
(defun function2 (local1 local2)
   ;; blah blah
)
;; This is the custom command you want to run:
(defun c:RUN (/ this that)
  (setq this "this" that "that")
  (function1 this nil)
  (function2 nil that)
  (command "_.dosomething")
  (princ)
)
;; Invoke the custom command:
(c:RUN)
(princ) ;; end of AutoLisp file

John F. Uhden

0 Likes
Message 4 of 4

Kent1Cooper
Consultant
Consultant

If it's something you want to do only once, and immediately upon loading, and don't need to be able to type in a command name later to do it again, then you can skip defining it into a command and then invoking that command, and just do it directly.  The entire file could be something like this, with no (defun)'s at all:

 

(alert "This routine honks the horn\nand rolls down the windows.")

(setq cmde (getvar 'cmdecho))

(setvar 'cmdecho 0)

(setq

  option1 (getwhatever this that other)

  point1 (getpoint "\nLocation: ")

  option2 (getsomething "'nTell me about it: ")

  point2 (getpoint "nOther location: ")

)

(command

  "_.this" option1 point1

  "_.that" option2 point2 "stringA"

  "_.qsave"

)

(setvar 'cmdecho 1)

(princ)
Kent Cooper, AIA