Monday, October 3, 2016

Enough with doing things in Autolisp. It is time for being things in Autolisp.

When people mention Autolisp automation they usually refer to custom macros used to reduce keystrokes. And to be fair, that is how I started with Autolisp. It was actually a very long -LAYER command to turn on and off drawing layers.

That was fine for a while until I started to realize that Autolisp functions are really like Lego blocks. They can fit together into amazing things. For years I was using Autolisp just that way. Do this. Do that. What programmers call programming procedurally. It was all about what the program will do. Now I am seeing there is another side. Programming declaratively. Be this. Be that. It is a different way of thinking. The idea is to list what is true in what I call a truth table, and then list the rules that govern how these true statements relate to each other. Then I can ask questions about the things that are true and the program will reason and hopefully give an answer. Or in my case draw a correct solution.

Monday, January 4, 2016

Easily turn your actions into Autolisp macros

The way I usually built my Autolisp macros was to study how I drew something. This is a study in slow motion because you are actually trying to capture each step. It is somewhat easier when you use the command line because what you draw is mostly what you type.
I would start by drawing two columns on a scrap piece of paper. I would record what I type at the command line on the right column and AutoCAD's reply on the left column. This would help me remember each step for writing the Autolisp macro.
As an example, say I drew a line with two points and hit enter to finish the LINE command:

                   | LINE
-------------------|------------------
Pick first point:  | point 1
Pick next point:   | point 2
Pick next point:   | enter

This allows me to turn this into a macro. I can pause my macro twice and wait for the user to pick a point then end the LINE command my passing a space " " which acts like pressing enter:

(defun c:drawline ( / )
    (command "LINE" pause pause " "))

Using this system you can capture the actions you use to draw for most tasks. Happy coding.