DraftSight 2020 Using Lisp to Customize Commands

Over the last couple of blogs, I’ve spoken about ways you can customize your DraftSight 2020 experience.  In today’s blog, I’ll talk about another – LISP.

So, what is LISP? LISP is a programming language that has been around since the late 1950’s.  Yes, you read that right, it’s over 60 years old! With regards to CAD software, I’ve been using LISP since the early 90’s to customize my experience.

So, what can you do with LISP?  Well, first off, to use LISP, you must be using DraftSight Professional or Premium – it is not supported in DraftSight Standard.  If you are running either of those, LISP will allow you to create your own programs to run inside of DraftSight 2020. Best of all, you only need Notepad or any other simple text editor to create your LISP routines.

For example, the LISP routine below will allow you to isolate a layer in your drawing:

; To isolate a layer

(defun c:iso ()
(setq ss (ssget))
(setq NoEnties (sslength ss))
(setq Entstuff (ssname ss 0))
(setq Entstuff (entget Entstuff))
(setq NewSetLayer (cdr (assoc ‘8 Entstuff)))
(command “layer” “s” NewSetLayer “”)
(command “layer” “f” “*” “”)
(setq i 0)
(while (< i NoEnties)
(setq ThawLayer (ssname ss i))
(setq ThawLayer (entget ThawLayer))
(setq ThawLayer (cdr (assoc ‘8 ThawLayer)))
(command “layer” “t” ThawLayer “”)
(setq i (+ i 1))
)
)

To load a LISP routine, first go to the Manage tab and click on Load Application.

In the dialogue box, select your LISP routine and click on Open.

The next step is to run the LISP routine.  To do this, you need to know the command name.  If we take a look at the first line of code in the LISP routine above, you will see (defun c:iso ().  That shows us the command name, ISO.  Sometimes, depending on the routine, you might receive a prompt in the Command Window telling you the command name.

The next step is to run the command. At the Command Window, enter ISO and hit enter.  The command loads and you can click on the layer you would like to isolate and hit enter or right click the mouse. You can see the routine in action below.

That’s just a very simple example of how you can make Custom commands within DraftSight 2020 Professional and Premium.  Because LISP has been around for so long, there are 1000’s of LISP routines available on the internet.  Just head over to your preferred search engine and start trawling through the links. If you’d like to learn how to program in LISP, take a look at CADOASIS, they have some excellent tutorials on learning LISP for DraftSight.

Learn more about DraftSight here.

MJ Smyth
The first time I used CAD, it was on a DOS PC with an 8088 processor, 640K of memory and a Hercules Mono Graphics Card... That, well that was a long long time ago. I switched to DraftSight the day it was released and haven't looked back!
MJ Smyth

Latest posts by MJ Smyth (see all)