Friday, December 12, 2008


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.

;--loaded functions

(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

;Auckland NZ;

Rev 0 date 16.6.95;

This program isolates a layer by picking it

(defun c:IL()

(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

(princ);exits cleanly

);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.


AutoCAD-IntelliCAD said...

Yes, I totally agree. AutoLISP rules. I like that AutoLISP has no type casting on variables. You can do some real crazy sh#$ with that! Its great as long as you don't muck it up with Visual LISP. Then it can't be run on anything but AutoCAD, and I can't afford $4000.00. I use progeCAD IntelliCAD ($375 USD) and have run into times when I couldn't run customers routines because of the short sighted, proprietary thinking of the folks in Sausalito. That, and their custom objects that render most programs showing proxies out of the DWG files, and customers can just about say goodbye to interoperablity. Luckily, progeCAD IntelliCAD can read and render objects in ADT, MDT, and Civil 3D DWG files.

William Le Couteur said...

Well,hmm...I have never heard of progeCAD. I have tried another one of the autocad clones, and just about burst into tears using it!
Which has put me off clones. Maybe one bad clone should not?

AutoCAD-IntelliCAD said...

Well, there was a time in the past where the IntelliCAD product was not lets say, up to snuff. But there was some big changes in the organization around 2005 and they got their stuff together. progeCAD IntelliCAD is now a reliable low cost replacement for AutoCAD and AutoCAD LT. The ITC (IntelliCAD Technology Consortium) is bringing out a totally rewritten version first to second quarter next year including a clone of ARX. Should prove interesting! Try out the 30 day trial download and I bet its not as bad as you think, and at 1/10 the price you dont have to sell your car to get it!

Anonymous said...

Bricscad is wihtout doubt the best alternative platform for applications today. They support LISP, COM/VBA, DCL, and even ObjectARX in a code compatible way. So you don't need to convert or rewrite any of your source code, you simply compile for Bricscad and/or Acad based on the same source code set. You might want to try it, their website is You can find a whole list of already ported applications there. I believe their developer reference guide is also available on the website.

seo said...

Web MarketingWeb SolutionsInternet Marketing ProfessionalsShoppingWeb DirectoryWeb DirectoryQuality Web DirectorySEOSEOTrave guideonline marketingadsvianet shopvianetCasinotraveletourspecialplannerHealth care

sbwebxweb d pets armorvenueesi
g eventEventbeautyparlorseoWebdirectorySEO directory

seo said...

we have established a platform of Engineering or our client and partner who can look for any type salutions related to Application Technology

seo said...

ProBizX is a professionally managed group specialized in all types of business consulting salutions offering its client globally Committed to calculated exceptional Marketing trustworthy and secure salution for the our clients.