AutoCAD LISP, converting blocks to points

Following up on my previous post on Starting developing for AutoCAD, I’ll show you how to use LISP in AutoCAD to convert a selection of blocks to a set of points.

Before I start, it is important to learn that all variables in LISP are global unless they are forced into being local inside the function definition. This is how we create local variables:

The are two reserved prefix letters for functions in LISP; “c:” and “s:”. C is for making the function accessible from the command line, S is in connection with the startup routine of AutoCAD. You don’t need to know that yet.


In the following code, I’ve added some error handling to my template by creating a custom error handler to display any potential error that might occur. After finishing the function, I reset the *error* variable which hold AutoCADs regular error handle function unless it is overridden like I’m showing here.

As stated in the previous post, it’s extremely important to properly handle the system variables before you start doing manipulation of entities, otherwise you will end up snapping to all the wrong places.

LISP is wonderfull in the way that it allows you to use all regular AutoCAD commands you normally do manually, and call them in a script or function. Commands involving user input forms will however be more intriguing.

Then it’s nice to know that most AutoCAD command have an alternate version with the dash (-)prefix. Eg: the LAYER command has an equivalent -LAYER command which allows you to pass parameters to it through LISP.

What if you would like to convert the blocks to Civil 3d COGO-points instead? Stay tuned for the next post;)