Autolisp Lessons

What is Autolisp ?

Autolisp is one of the programming languages of Autocad. Step by step example course for Autolisp.

  1. Step 1: About Autolisp

    Autolisp is one of the programming languages of Autocad.

    Autocad also supports the Visual Lisp programming language.

    Autolisp '' Lisp '' is the programming language adapted to the Autocad.

    LISP is a programming language for artificial intelligence.

    The file extension used for Autolisp is .lsp.

    The contents of this file extension can be viewed / edited in any text editor ...

  2. Step 2: Uploading and run autolisp files

    The appload command is used to load the Autolisp files. In the Autocad, the appload command is written from the keyboard. Or run the command from the Autocad drop-down menu.

    The file file contains the file you want to load. Select and press the "load" button. An information message usually appears in the Autocad command line. The message that the related file is loaded is displayed.

    The Autolisp file that is loaded has a command name for the program in question. By typing this command name from the keyboard, the installed program is executed.

    The command name is usually the expression after "c:".

    For example:

    (defun c:your-command-name ()

    sometimes you can see that way too :

    (defun c:your-command-name (/ pt1 pt2 pt3 pt4)

    Sometimes the command name is used without "c:".

    In this case, the program is written as follows:

    (defun your-command-name ()

    (defun your-command-name (/ pt1 pt2 pt3 pt4)

  3. Step 3: Autolisp editor

    I will talk about Autolisp program writing techniques. I mean, how do we write, where do we write? There are many options for this topic.

    a) The 'Visual Lisp Editor' found in Autocad. This is the best option.

    b) Use any of the editor programs such as Notepad plus, Editplus, TotalEdit, TextPad, Lisp Pad..

    c) Handwriting on A4 paper, later write on the computer.

    A variety of text editing / editing programs are available to help you. But no one is like 'vusual lisp editor'. It works, but to some extent.

    With Vusial Lisp editor, you write programs and test if it works. You write programs with text editor programs, but you cannot test the accuracy of the program.

    In spite of everything, these text editor programs are very beautiful. Color codes, automatic word completion feature, precision on brackets ..

  4. Step 4: Sample 1

    ; Sample first program

    (defun c:mysample1 ()

    (princ "\n Hello World \n ")


    (Princ "Use command name > mysample1 < ! [] ")

    Program description :

    1) Command name is mysample1. After 'c:' you see command name.

    2) This autolisp program allows you to see a message on the autocad screen. The message content is 'Hello World'.

    3) With 'princ' command we have the message shown on the command line.

    4) In the program we have created, the number of open brackets is as much as the number of closed parenthesis! This is a very important issue. :-)

  5. Step 5: Sample 2

    ; Line drawing coding

    (defun c:line1 (/ pt1 pt2)

    (setq pt1 (getpoint "\n Click the screen for the first point ?! :"))

    (setq pt2 (getpoint "\n Click the screen for the second point ?! :"))

    (command "line" pt1 pt2 "")



    (Princ "Use command name > line1 < ! [] ")

    Information about this Autolisp program :

    1) The expression after c: in the first line is the command name. So the command name is set to line1.

    2) With the Setq command we defined two successive statements. We called pt1 and pt2 for this phrase. Pt1 means point1, that is to say coordinate point 1. Pt2 means coordinate point 2.

    3) With the Getpoint command, we asked the user to click on the screen. When we clicked on the screen, we defined a specific coordinate point to the pt1 statement with the setq command.

    4) What we call a coordinate is actually x, y, z coordinate. I had to make the selection for the line start and end point. We did this in this program.

    5) We did the line drawing with the expression 'Command'.

    6) Before the end of Autolisp program we used the princ command.