Jeffrey Whitney
Jeffrey Whitney

Reputation: 25

How do I run autolisp from commandline in autocad?

This is driving me nuts because I did this successfully once, but can't remember how the heck I did it. I have a lisp routine that is already loaded. In fact, it's loaded at startup. All well and good. Now I want to make it so that I can type a command and have it call that lisp routine. I thought it was "Command Aliases" in the "Express Tools", but it can't be that for the simple reason that it doesn't list the LISP programs that I have loaded. Yet, I have another lisp routine that I can activate by typing a command in the command line, so like I said, I did this once successfully already, I just cannot for the life of me figure out how the heck I did it. I've tried going into CUI to do it, but I can't figure it out.

Please help.

Upvotes: 1

Views: 65

Answers (1)

Spencer Barnes
Spencer Barnes

Reputation: 2877

There are two ways to achieve this.

  1. If you do not need to pass arguments to your routine, use the method outlined in Lee Mac's comment prefixing your function name with c:. So
(defun myfunction ()
... ;stuff
)

becomes

(defun c:myfunction ()
... ;stuff
)
  1. If you do need arguments passed to your routine, start your commandline entry with an opening bracket as if it's a valid LISP clause. When complete the command line will echo the evaluation of whatever you typed in (negating the need for princ to see the value)
    So, you could type in command line:
(myfunction "arg1" var2 3.0)

and your function will be called with a string argument "arg1", the contents of a saved variable var2, and the real number 3.0

Upvotes: 0

Related Questions