Nate's Simple AutoLisp -
Lesson 001
(
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!
Nate's
Simple AutoLisp - Lesson
002
Nate's
Simple AutoLisp - Lesson
003










