One click

There was an interesting post on Hacker News a few days ago: What is the most impactful thing you’ve built? It reminded me of my earliest memorable programming achievement, one that I’m still proud of and that predates my full-time IT career by a couple of years.

During one of my undergraduate years, I was a part-time AutoCAD technician at a small consulting firm. My primary job was to digitize blueprints. I would take facility blueprints provided by clients, tape them to a large digitizer, and trace them with a special multi-button mouse to create an AutoCAD drawing. Then I had to measure the area of each room in the facility and enter that information into a database. The work required a lot of mouse clicks, and we had a library of custom functions written in AutoLISP to reduce some of the overhead. The buttons on the mouse were programmed to run common commands and functions so that you didn’t have to constantly move your mouse to a toolbar button or switch over to the keyboard to type commands.

When the technician who had been maintaining the custom functions left the firm, my boss tapped me to take over that role in addition to my primary duties. I wasn’t a computer science major, but my computer skills were above average and I had taken one or two programming classes, so I guess he thought I was qualified. I had never seen any LISP dialect before, and it was very confusing at first. Fortunately, AutoCAD came with good documentation, and the firm had subscriptions to two CAD magazines that contained AutoLISP tutorials and sample code. Eventually I learned enough to start enhancing the existing functions and writing new ones.

My boss had told me when I took over the role that his holy grail was a one-click area function. He had wanted it for years, but none of the previous technicians (at least one of whom was a computer science major) had been able to crack it.

For a little background, to measure the area of a space in AutoCAD, you invoked the “area” command and clicked each corner in the space. It wasn’t a big deal in a small rectangular room, but in a large room or a room with a lot of corners, measuring the area required quite a bit of mouse movement across the large digitizer. My boss wanted to be able to click once anywhere inside of a space and have the area measured automatically. It may not seem like a big deal — and I confess that at the time, I didn’t think it was — but when you’re dealing with a large university that may have handed you dozens of blueprints, small time savings add up.

I read a lot of sample code in the CAD magazines, and I scoured the AutoCAD documentation to no avail. Then one day, I remembered (or discovered; I’m not sure which) that area is one of the properties of a hatch. And you can hatch a space by clicking anywhere inside of it. (Hatching a space is like filling a shape with a pattern; the hatch is the fill.) I wrote a function that worked like this: When you clicked inside the space, it would automatically hatch the space, get the area of the hatch, and erase the hatch. It was kludgy and inelegant, and it didn’t work if the space contained an arc. (I never did figure out why.) But about 90 percent of the time, it reduced measuring area to one click.