Nate Holt's Blog

July 5, 2009

Nate’s Simple Autolisp – Lesson 001

Filed under: Tutorials — nateholt @ 10:42 am


(note: originally appeared July 2006 on the old blog)

Warning/Disclaimer: I’m neither a teacher nor am I versed in the theory behind AutoLisp programming. But I invite you to come along for a ride. This stuff is not only fun, but it can be useful ! Each lesson should take 5-10 minutes.

So, here we go…

Lesson 001 – Picking stuff

We’ll start out simple, nothing fancy. We’ll just type and run AutoLisp expressions right at your AutoCAD “Command:” line prompt.

1. Open up an AutoCAD drawing. Draw a LINE entity anywhere.

2. At the Command: prompt type this… (entsel) [Enter]


3. As soon as you hit the [Enter] key, AutoCAD evaluates what you’ve typed on the command line. The word “entsel” inside of the open and close parenthesis is a predefined AutoLisp function for picking stuff, one thing at a time. It defaults to a “Select object:” prompt. Now pick on the LINE entity in your drawing.

You will see something like this displayed on your command line:


It is a “list” of two pieces of data. Only the first element is of interest to us now. It’s a numeric code that gives the entity name identifier of the LINE entity you selected.

Okay, let’s dig a bit deeper.

We need to isolate this entity name from the two-element list returned by (entsel).

4. Type this at the command line prompt: (car (entsel)) [Enter]

5. Pick on a line entity. Now you’ll see the entity name code all by itself. The “(car … )” AutoLisp function returns the first element of a multi-element list.


Now, the cool part. We’re going to “open” up and display the guts of a picked entity.

6. Type this at the command line prompt: (entget (car (entsel))) [Enter]

7. Pick on a line entity. Now you’ll see a bunch of data displayed in your command window. It will look something like this:


At first it just looks like gibberish. But there is some interesting stuff in here. Let’s poke around.

This is the basic data about our picked LINE entity. It is a “list” of stuff. Each element of this list starts with a group code number followed by the value for that group code.

Group code 0 give the entity type. Look at the data and pick it out. You’ll see (0 . “LINE”). So, we picked on a LINE entity.

For a LINE entity, group code 10 gives the line’s staring X,Y,Z coordinate. Look for the (10 ….) entry in the data dump. The data following the 10 is the starting X,Y,Z coordinate. Group code 11 gives the ending X,Y,Z coordinate.

Group code 8 gives the layer name that the entity is inserted on.

Okay, that’s all for now. Time’s up. Hope to see you for the next lesson!



  1. […] previous postings: Lesson 001, Lesson 002, Lesson 003, Lesson 004, and Lesson […]

    Pingback by Nate’s Simple AutoLISP – Lesson 006 « AutoCAD Electrical Etcetera — September 26, 2009 @ 4:52 pm

  2. I can´t see the images from lesson 001, 002 and 003, the link don´t have the images anymore?

    Comment by Alexandre Tadashi Lara Murai — June 8, 2014 @ 9:46 am

    • Yes, these were part of an Autodesk sponsored blog from long ago. Not sure if Autodesk would be able to find an archive copy. Sorry. Maybe I’ll have to try to rewrite them. Does anyone have a hard-copy? — Nate.

      Comment by nateholt — May 2, 2015 @ 6:22 am

RSS feed for comments on this post. TrackBack URI

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

Blog at

%d bloggers like this: