Content on this page requires a newer version of Adobe Flash Player.

Get Adobe Flash player

AutoCAD Tutorial Logo AUTOCAD .pgp vs LISP

You may be aware of the .pgp file in AutoCAD that allows users to customise & re-assign common AutoCAD commands to other letters than the default ones. For instance, the default command for Circle is 'c', but in the .pgp file we can change this to any key(s) we like. This is handy for simple customising but what if you want to create a circle by typing cc, change it's colour to red, and make it a 1200 diameter? Pgp commands can't do that but LISP routines can. The code below shows an example of how we can do this using LISP, don't be over whelmed by looking at the code, it is really quite easy. Open Notepad (or similar program) Goto File, Save As and name the file FirstLisp.lsp somewhere on your hard drive - Note that the extension is .lsp - This is the file extension of LISP files.

1__(defun c:cc ()
2__(command "cecolor" "red" "circle" pause "d" "1200")

Basic break down of the code is:
Call routine
Do commands we have specified
End routine

Let's start by looking at line 1 (defun c:cc ()
First thing to notice is the bracket (parenstheses) ( - All LISP programs/scripts start with a ( - That's just a rule.

Next is the word defun - This is telling AutoCAD this is a function (or the start of the program/script). All LISP programs require a place telling AutoCAD where the start of the function (program/script) begins. Again, this is a bit of a rule so all LISP programs must at least have (defun in them to begin a function (program/script).

Next is c:cc - the first c & colon : represents the AutoCAD command prompt. Bascially the first c is shorthand for command in the AutoCAD command prompt. Just open AutoCAD and have a look at the command prompt, you will see Command: the c: is shorthand for this.

After the c: comes cc. The cc is what we are going to call the new command we are now creating in LISP. We can call this anything we want. When we type cc in AutoCAD, the program/script will be called to work. (In this case we will be creating a red circle at 1200mm diameter)

Lastly, line 1 finishes with (). All functions end with this. These parenstheses have a use for more complex program but that is for a more advanced tutorial.

Second line is where the actual work happens. We can see that we start with ( on the second line and end with ) . In between the parenstheses we call some common AutoCAD commands to work.

The first word is Command - this means the same as the AutoCAD command prompt. You will notice though that instead of using the shorthand c: as we did on line 1 of the above code, we use the word Command.

"cecolor" "red"
Our first command is cecolor, this is an AutoCAD text based command that asks the user what color they want to change the pen colour to. Notice the command name is written between quotation marks " ". All AutoCAD native commands are written between quotation marks, but not everything is,as you can see with the word pause in the code and also variables we will look at in a later tutorial. Next I call "red", this is telling the command 'cecolor' what colour we want the pen to be. In this case I have written the word red, but you can use any AutoCAD colour number from 1-255 instead of the word.
Just for your reference the names of colours that can be typed are: red,yellow,cyan,green,magenta,white,blue

"circle" pause "d" "1200")
Next part of the script is calling the AutoCAD circle command. Once we have called the circle command, the word 'pause' is written without being enclosed in quotation marks. What this does is pause the rest of the program until the user has responded to the active command. Basically what is happening here is the circle command is called, then the command asks the user to pick the center point location of the circle we want to create. Once you have selected the position on the AutoCAD screen, the rest of the command finishes. In this case, the letter "d" is called (short for diameter) then the program asks for the diamter dimension which we enter as "1200". This whole LISP routine is really just a series of commands all chained together. You could basicaly have typed all the commands manually at the AutoCAD command prompt but by putting it in LISP, it can be fully Automated.

We finish off Line 2 with another parenstheses ) then another one on Line 3 to end the routine (program/script)

>>>>2. AutoCAD LISP - Loading LISP Files