;;; DIMFL - Shorten the extension lines of selected dimensions.
;;;
;;; Applies a per-dimension override of DIMFXLON / DIMFXL, so the extension line
;;; starts at a fixed distance from the dimension line instead of at the
;;; definition point. Fixes the dimensions you pick, not the whole style.
;;;
;;; NO MEASUREMENT CHANGES. Definition points are not moved; only how far the
;;; extension line is DRAWN. A 50 stays a 50.
;;; Reversible with the Restore option. One Ctrl+Z undoes the whole pass.
;;;
;;; WARNING: if a dimension looks wrong because its definition point MOVED, this
;;; fixes the look but not the value, and makes the error harder to spot. Check
;;; the numbers before shortening anything.
(vl-load-com)
(defun R0:DFL-Get (obj prop / r)
(setq r (vl-catch-all-apply 'vlax-get (list obj prop)))
(if (vl-catch-all-error-p r) nil r))
(defun R0:DFL-Put (obj prop val / r)
(setq r (vl-catch-all-apply 'vlax-put (list obj prop val)))
(not (vl-catch-all-error-p r)))
;; (logand 4 nil) throws, so a missing layer record answers "not locked".
(defun R0:DFL-Bloqueada (en / cap)
(setq cap (tblsearch "LAYER" (cdr (assoc 8 (entget en)))))
(and cap (= 4 (logand 4 (cdr (assoc 70 cap))))))
;; Default length = whatever the first picked dimension already carries. Whoever
;; set up the style usually chose a number that suits the drawing scale.
(defun R0:DFL-Sugerido (ss / i en obj v)
(setq i 0 v nil)
(while (and (< i (sslength ss)) (null v))
(setq en (ssname ss i) i (1+ i)
obj (vlax-ename->vla-object en)
v (R0:DFL-Get obj 'ExtLineFixedLen))
(if (or (not (numberp v)) (<= v 1e-9)) (setq v nil)))
(if v v 2.5))
(defun c:DIMFL ( / *error* ss i en obj largo sug modo hechos fallo bloq und doc)
(defun *error* (msg)
(if und (vl-catch-all-apply 'vla-EndUndoMark (list doc)))
(if (and msg (not (wcmatch (strcase msg) "*CANCEL*,*QUIT*,*BREAK*,*EXIT*,*ABORT*")))
(princ (strcat "\n[X] DIMFL: " msg)))
(princ))
(princ "\nDIMFL | Shorten extension lines (no measurement is changed).")
(princ "\n Select dimensions: ")
(if (null (setq ss (ssget '((0 . "DIMENSION")))))
(princ "\n[!] DIMFL: nothing selected.")
(progn
(princ "\n Shorten = fixed length extension lines")
(princ "\n Restore = back to starting at the definition point (LONG again)")
(initget "Shorten Restore")
(setq modo (getkword "\n [Shorten/Restore] <Shorten>: "))
(if (null modo) (setq modo "Shorten"))
(if (= modo "Shorten")
(progn
(setq sug (R0:DFL-Sugerido ss))
(initget 6)
(setq largo (getdist (strcat "\n Extension line length <"
(rtos sug 2 3) ">: ")))
(if (null largo) (setq largo sug))))
(setq doc (vla-get-ActiveDocument (vlax-get-acad-object)) und T)
(vla-StartUndoMark doc)
(setq i 0 hechos 0 fallo 0 bloq 0)
(while (< i (sslength ss))
(setq en (ssname ss i) i (1+ i))
(if (R0:DFL-Bloqueada en)
(setq bloq (1+ bloq))
(progn
(setq obj (vlax-ename->vla-object en))
;; ExtLineFixedLen = DIMFXL, ExtLineFixedLenSuppress = DIMFXLON.
;; Despite the "Suppress" name the value follows DIMFXLON: 0 = off
;; (long lines), -1 = on (fixed length). Length first, switch second.
(if (= modo "Shorten")
(if (and (R0:DFL-Put obj 'ExtLineFixedLen largo)
(R0:DFL-Put obj 'ExtLineFixedLenSuppress -1))
(setq hechos (1+ hechos))
(setq fallo (1+ fallo)))
(if (R0:DFL-Put obj 'ExtLineFixedLenSuppress 0)
(setq hechos (1+ hechos))
(setq fallo (1+ fallo))))
(vl-catch-all-apply 'vla-Update (list obj)))))
(vla-EndUndoMark doc)
(setq und nil)
(princ (strcat "\n\n[OK] DIMFL: " (itoa hechos) " dimension(s) "
(if (= modo "Shorten")
(strcat "with a " (rtos largo 2 3) " extension line")
"restored: their lines are LONG again")))
(if (> bloq 0) (princ (strcat "\n " (itoa bloq) " on locked layers: skipped.")))
(if (> fallo 0) (princ (strcat "\n " (itoa fallo) " did not accept the change.")))
(if (= modo "Shorten")
(princ "\n No measurement changed. To revert: DIMFL, Restore option.")
(princ "\n To shorten them again: DIMFL, Shorten option."))))
(princ))
(princ "\n[DIMFL] loaded. Type DIMFL to shorten extension lines.")
(princ)