08-01-2022
06:32 PM
- Marcar como nuevo
- Favorito
- Suscribir
- Silenciar
- Suscribirse a un feed RSS
- Resaltar
- Imprimir
- Denunciar
08-01-2022
06:32 PM
Here's a vlisp program that writes the equation of a line at its midpoint. If the line is within approximately 0.001° of being vertical the note "VERTICAL LINE" is added.
(defun c:eqn (/ ed e1 e2 dx m b sgnm sgnb msg midpt)
; determines the equation for a line in the format y = mx + b
; and writes it at the line's midpoint
; L. MINARDI 8/1/2022
(setq ed (entget (car (entsel "\nSelect line.")))
e1 (cdr (assoc 10 ed))
e2 (cdr (assoc 11 ed))
)
(setq dx (- (car e2) (car e1)))
(setq ang (angle e1 e2))
(If (> ang pi)
(setq ang (- ang pi))
)
; check if line is almost vetical
(if (equal ang (/ pi 2.) 0.0001)
(setq m nil)
(setq m (/
(- (cadr e2) (cadr e1))
dx
)
)
)
(if m
(progn
(setq b (- (cadr e1) (* m (car e1))))
(if (> m 0.0)
(setq sgnm "+ ")
(setq sgnm "- ")
)
(if (> b 0.0)
(setq sgnb "+ ")
(setq sgnb "- ")
)
(setq
msg (strcat "y = " (rtos m 2 3) "x " sgnb (rtos (abs b) 2 3))
)
)
(setq msg " VERTCAL LINE")
)
(setq midpt (mapcar '/ (mapcar '+ e1 e2) '(2. 2. 2.)))
(command "_text" midpt "" "" msg)
(princ)
)
lee.minardi