AutoLISP: Dimension Extension Line Toggle

Simple and sweet. This one is one that I use all of the time when I have dimension extension lines that overlap objects in my drawing. Before i found this LISP, I used the properties palette to achieve this. But now, I can do it in a matter of a single click of the mouse.

Here’s how:

  • XLTGL <enter> to start (Extension Line Toggle)
  • Click on the extension lines to toggle off.
  • Click on the dimension nearest the side to turn back on

;; ; XLTGL.LSP, Version 1.01
;;; By Walt Bedinger
;;; 08/14/2010
;;; This routine toggles dimension extension lines off and on.
;;; To use, select the dimension line toward the end where you want the extension line to be hidden or unhidden.
;;; To exit, pick away from any object.
;;; Occasionally the routine does not work. As best I tell, entsel isn't reporting a new object if the same point is picked
;;; twice in succession. It probably won't matter unless you are toggling the same dimsnsion line repeatedly just for fun.
;;; There is no error routine. Not much can go wrong. There is no provision for undoing, either: if you don't like the
;;; result, just pick the same dimension again to change it back. It's quicker and easier than an undo.
;;; Inspired by the work of Herman Mayfarth and Kent Cooper, published in Cadalyst Magazine as Tips 1572 and 1671
;;; Main Routine.
(defun C:XLTGL () (XLTGLSEL)) ; All this does is call the object selection subroutine,
; which in turn calls the action subroutine when it's needed.
;;; End of the main routine.
;;; Subroutines
(defun XLTGLSEL (/ obj objName objData pickPoint)
(while (setq obj (entsel)) ; The routine will remain active so long as the user keeps
(setq objName (car obj) ; picking objects.
objData (entget objName '("ACAD"))
pickPoint (cadr obj)
(if (equal "DIMENSION" (cdr (assoc 0 objData)))
(XLTGLACT objName objData pickPoint)
) ; If a dimension was selected,
) ; call XLTGLACT.
(defun XLTGLACT (objName objData pickPoint /
distance1 distance2 side hideOverride
extenData extenList flag
(setq distance1 (distance pickPoint (cdr (assoc 10 objData)))
; Distance from pickPoint to the 2nd end of the dim line.
distance2 (/ (cdr (assoc 42 objData)) 2)
; Half of the dimension length.
(if (> distance1 distance2) ; If the pick point is dead center, this will give a false
(setq side "DIMSE1") ; result; but what are the chances of that?
(setq side "DIMSE2")
(setq hideOverride "ON") ; Assume that we want the extension line to be hidden.
; Then check that assumption.
(if (setq extenData (assoc -3 objData))
; If either extension line has previously been hidden,
(progn ; even if it is not hidden now, AutoCAD has appended
(setq extenList (cdadr extenData)); extended data to the object. This section looks at the
(foreach pair extenList ; extended data (if any); and if the extension line is
(if flag ; already hidden it tells the routine to unhide it.
(progn ; In the extended data, a (1070 . 75) or a (1070 . 76)
(setq flag nil) ; dotted pair means that the following dotted pair will
(if (equal (cdr pair) 1)
(setq hideOverride "OFF")
) ; indicate if the hide override is on or off. (1070 . 0)
) ; means it is off. (1070 . 1) means it is on. 75 refers to
(if (equal side "DIMSE1") ; extension line 1 and 76 to extension line 2.
(if (and (equal (car pair) 1070) (equal (cdr pair) 75))
(setq flag T)
(if (and (equal (car pair) 1070) (equal (cdr pair) 76))
(setq flag T)
(command ".dimoverride" side hideOverride "" objName "")
; This command does the job of hiding or unhiding.
;;; End of Subroutines.
(princ) ; Causes the routine to load without fanfare.

About AutoCAD Tips

This blog serves as a knowledge base for myself (and anyone else) so that I can reference tips & tricks that I have learned and also refer others to it as well. I hope that this blog helps you learn at least one tip to make your drafting/design experience better.
This entry was posted in AutoLISP, Dimensions, Modifying, TIPS. Bookmark the permalink.

2 Responses to AutoLISP: Dimension Extension Line Toggle

  1. George says:

    The routine looks great! How can I download it to my computer? I tried to copy and paste the code but get line numbers with the rest of the text.

  2. George says:

    I found the answer in one of your posts. I was able to copy the source code without any problems. Thanks!

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s