[FONT=courier new]
(defun c:d (/ p0 p1 p2 ang ent p10a p11a entst)
(setvar "cmdecho" 0)
(ai_undo_push)
(setvar "osmode" 47)
(mlay "dim" "3")
(initget 128)
(setq p0 (getpoint "\nSpecify first extension line origin or [Align/< Select line to align>] :")
entst (entlast)
)
(if (null p0)
(setq p0 "S")
)
(if (= (type p0) 'str)
(progn
(cond
((= (strcase p0) "S")
(setq ent (nentselp "\nSelect line :"))
(while (null ent)
(setq ent (nentselp "\nSelect line :"))
)
(while (/= (cdr (assoc 0 (entget (car ent)))) "LINE")
(setq ent (nentselp "Object selected is not line .\nSelect line :"))
)
(if (= (nth 3 ent) nil)
(progn
(setq p1 (trans (cdr (assoc 10 (entget (car ent)))) 0 1)
p2 (trans (cdr (assoc 11 (entget (car ent)))) 0 1)
ang (* 180 (/ (angle p1 p2) pi))
)
)
(progn
(matrix_b ent)
(setq p1 (trans p10a 0 1)
p2 (trans p11a 0 1)
ang (* 180 (/ (angle p1 p2) pi))
)
)
)
)
((= (strcase p0) "A")
(setq p1 (getpoint "\nSpecify first extension line origin :")
p2 (getpoint p1 "\nSpecify second extension line origin :")
ang (* 180 (/ (angle p1 p2) pi))
)
)
)
(princ "\nSpecify dimension line location :")
(command "_.dim1" "rotated" ang p1 p2 pause "")
)
(progn
(setq p1 (getpoint p0 "\nSpecify second extension line origin :"))
(princ "\nSpecify dimension line location :")
(command "dimlinear" p0 p1 pause)
)
)
(if (not (equal entst (entlast)))
(progn
(replace_ch "dim" 256 "bylayer" (entlast))
(entmod (subst
(cons 51 0)
(assoc 51 (entget (entlast)))
(entget (entlast))
)
)
(setq dimtxt (cdr (assoc 42 (entget (entlast)))))
(princ (strcat "\nDimension text = " (rtos dimtxt)))
)
)
(ai_undo_pop)
(setvar "cmdecho" 1)
(princ)
)
[/FONT]