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.

No comments:

Post a Comment