This will be a short series of posts, concentrating on Autolisp routines that I have written.
I will attempt to provide routines that are heavily commented, so you can understand how they work.
My first point is that you do not have to be a genius to write lisp routines (?!) and that you can get quite a lot of satisfaction out of just a few lines of code.
It has been usable with every version of Autocad that I can remember, and one of it's chief advantages is that most routines will run on any version. Unlike visual basic for applications (VBA).
The implementation is easy and elegant: you get Notepad (have a look under Accessories on your Windows PC) up and running and start typing. To use, you can go "appload" in Autocad, but I prefer the lazy two screen approach: just drag and drop the file into autocad to load it.
Just remeber that file extension has to be lsp, so for instance it might be called cor.lsp.
This is a hangover from the MSDOS days and you may need to go to Windows Explorer and turn on the option that says "Hide file extensions for known file types" (Under Tools-Folder Options-View) . This is important because Notepad will save it's files with the extension .txt.
You will need to change that when saving, to .lsp.
Because blogspot don't allow file downloads, all routines will be shown in the blog post: you just cut and paste them into notepad.
One last "need to know": You need to create yet another file, always called acad.lsp.
This is a special file (again, just an easy text file) , that Autocad knows about and will check for.
If it finds it, it will load the routines listed in it so you have them all available at the command line when you need them.
Here is an example that you could cut and paste into Notepad, and, if you save it into
c:\program files\autocad\support directory (yours may vary slightly from this), it will make available the commands COR and IL. I use abbreviations to cut down the typing- COR stands for COPY AND ROTATE, and IL stands for ISOLATE LAYER. These are the two simple routines I am going to start you off on.
(defun C:cor () (load "c:/bilro/bilro1/cor")(c:cor))
(defun C:il () (load "c:/bilro/bilro2/il")(c:il))
What all the above stands for is that we are defining a function (hence defun) that can be used on the command line (hence the c:) and that part of this functions job is to load a lisp routine and make it available . It is a bit cryptic, but I find if you just follow this format, it always works.
Of course, all this loading is not much point if the routines cor and il don't exist at the path I have shown ie c:/bilro/bilro1/cor. Your path can be different-it does not matter where you keep them.
Setq - what does it mean? It just means "assign this to the said variable"
So, here is the code for COR.lsp:
;written by Bill LeCouteur-this line is just a comment -ignored by Autocad because of ";"
;this routine copies & rotates-this line is just a comment -ignored by Autocad because of ";"
(defun c:cor ()
(prompt "\nSelect the items to be copied and rotated: ")
(setq ss1 (ssget)) ;gets a selection set and sets it to a variable called ss1
(setq pt1 (getpoint "\nEnter rotation point for the picked items: ")) ;gets a user defined point
(command "copy" ss1 "" "0,0" "0,0") ; issues a standard autocad command-copy
(command "rotate" ss1 "" (list (car pt1) (cadr pt1)) pause); same again -pause is for user input
(command "redraw"); same again-standard command
(princ) ;exits cleanly
);this closes the parentheses at the start.
Here is the code for IL.lsp
;Program written by Bill Le Couteur
Rev 0 date 16.6.95;
This program isolates a layer by picking it
(setq edata(entget(car(entsel)))) ;gets the user to select an item and sets the variable edata to it
(setq thelayer(cdr(assoc 8 edata))) ;finds out the layer it's from by looking at edata
(command "-layer" "s" thelayer "");sets the current layer to that layer
(command "-layer" "f" "*" "");freezes every other layer
);end of defun
Whew! If you have got this far, you may have such enthusiasm that you might have actually attempted to do the above, so you may need help, so I have turned the comments on this blog to anyone can comment, and I will attempt to check this regularly and help if needed.