Lisp AutoCAD – Align Dimension

By | May 7, 2023

The topic today: Share Lisp AutoCAD – Align Dimension

The shortcut command is BD

Step to step use the following:

  1. Load Lisp
  2. Type BD and press Enter
  3. Select Dimensions and Enter
  4. Select Point to extend

Code Lisp:

(defun myerror (s) ; If an error (such as CTRL-C) occurs
; while this command is active…
(cond
((= s “quit / exit abort”) (princ))
((/= s “Function cancelled”) (princ (strcat “\nError: ” s)))
)
(setvar “cmdecho” CMD) ; Restore saved modes
(setvar “osmode” OSM)
(setq *error* OLDERR) ; Restore old *error* handler
(princ)
)
(DEFUN C:BD (/ CMD SS LTH DEM PT DS KDL N70 GOCX GOCY PT13 PT14 PTI
PT10 PT10I PT10N O10 N10 PT11 PT11N O11 N11 KC OSM OLDERR)
(SETQ CMD (GETVAR “CMDECHO”))
(SETQ OSM (GETVAR “OSMODE”))
(SETQ OLDERR *error*
*error* myerror)
(PRINC “Please select dimension object!”)
(SETQ SS (SSGET))
(SETVAR “CMDECHO” 0)
(SETQ PT (GETPOINT “Point to extend:”))
(SETQ PT (TRANS PT 1 0))
(COMMAND “UCS” “W”)
(SETQ LTH (SSLENGTH SS))
(SETQ DEM 0)
(WHILE (< DEM LTH)
(PROGN
(SETQ DS (ENTGET (SSNAME SS DEM)))
(SETQ KDL (CDR (ASSOC 0 DS)))
(IF (= “DIMENSION” KDL)
(PROGN
(SETQ PT13 (CDR (ASSOC 13 DS)))
(SETQ PT14 (CDR (ASSOC 14 DS)))
(SETQ PT10 (CDR (ASSOC 10 DS)))
(SETQ PT11 (CDR (ASSOC 11 DS)))
(SETQ N70 (CDR (ASSOC 70 DS)))
(IF (OR (= N70 0) (= N70 32) (= N70 33) (= N70 160) (= N70 161))
(PROGN
(SETQ GOCY (ANGLE PT10 PT14))
(SETQ GOCX (+ GOCY (/ PI 2)))
)
)
(SETVAR “OSMODE” 0)
(SETQ PTI (POLAR PT GOCX 2))
(SETQ PT10I (POLAR PT10 GOCY 2))
(SETQ PT10N (INTERS PT PTI PT10 PT10I NIL))
(SETQ KC (DISTANCE PT10 PT10N))
(SETQ O10 (ASSOC 10 DS))
(SETQ N10 (CONS 10 PT10N))
(SETQ DS (SUBST N10 O10 DS))
(SETQ PT11N (POLAR PT11 (ANGLE PT10 PT10N) KC))
(SETQ O11 (ASSOC 11 DS))
(SETQ N11 (CONS 11 PT11N))
(SETQ DS (SUBST N11 O11 DS))
(ENTMOD DS)
)
)
(SETQ DEM (+ DEM 1))
)
)
(COMMAND “UCS” “P”)
(SETVAR “CMDECHO” CMD)
(SETVAR “OSMODE” OSM)
(setq *error* OLDERR)
(PRINC)
)

Download Lisp here: Link 1, Link2

Thanks for visiting and reading AutoCADtip.com Blog!

Author: DungCEN

Thanks for visiting my blog!