Anuncios

The Autodesk Community Forums has a new look. Read more about what's changed on the Community Announcements board.

leeminardi
en respuesta a: psw1125

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.

leeminardi_0-1659403893664.png

 

(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