TheSwamp

Code Red => AutoLISP (Vanilla / Visual) => Topic started by: PM on February 18, 2021, 06:45:59 AM

Title: Heron formula-help with the code
Post by: PM on February 18, 2021, 06:45:59 AM
Hi.I am using this code for calculate area with Heron formula .

Code - Auto/Visual Lisp: [Select]
  1. (defun c:heron ( / tri-no p1 p2 p3 da db dc s E cp lst cnt fn fp Etotal)
  2. (setvar "OSMODE" 9)
  3. (command "_layer" "_m" "Heron's formula" "_c" "7" "" "")
  4.  
  5.   (defun tricent (pt1 pt2 pt3)(mapcar '(lambda (x y z) (/ (+ x y z) 3)) pt1 pt2 pt3))
  6.   (setq tri-no 0 Etotal 0)
  7.   (while (and (setq p1 (getpoint "\nP1 : "))(setq p2 (getpoint "\nP2 : "))(setq p3 (getpoint "\nP3 : "))
  8.               (setq da (distance p2 p3)) (setq db (distance p3 p1)) (setq dc (distance p1 p2))
  9.               (setq s (/ (+ da db dc) 2.0) ) (setq E (sqrt (* s (- s da) (- s db) (- s dc)))))
  10.     ; while valid points are given
  11.     (if (assoc (setq cp (tricent p1 p2 p3)) lst)
  12.       (prompt "\nPoint allready entered")
  13.       (progn
  14.         (setq lst (append lst (list (cons cp (list (setq tri-no (1+ tri-no)) s da db dc E )))))
  15.         (entmakex (list '(0 . "TEXT") (cons 10 cp) (cons 40 0.25) (cons 1 (strcat "E" (itoa tri-no)))))
  16.       )
  17.     )
  18.   )
  19.   (if (and (vl-consp lst) (setq fn (vl-filename-mktemp ".txt"))(setq fp (open fn "w")))
  20.     (progn
  21.       (foreach x lst
  22.         (setq x (cdr x) tri-no (nth 0 x) s (nth 1 x) da (nth 2 x) db (nth 3 x) dc (nth 4 x) E (last x))
  23.         (write-line
  24.           (strcat "E" (vl-princ-to-string tri-no) " = " "\U+221A" " " (vl-princ-to-string (rtos s 2 2 )) " x (" (vl-princ-to-string (rtos s 2 2))
  25.                   " - " (vl-princ-to-string (rtos da 2 2 )) ") x (" (vl-princ-to-string (rtos s 2 2)) " - " (vl-princ-to-string (rtos db 2 2 )) ") x ("
  26.                   (vl-princ-to-string (rtos s 2 2)) " - " (vl-princ-to-string (rtos dc 2 2 )) ") = " (rtos E 2 2) " sq.m" ) fp)
  27.         (setq Etotal (+ Etotal E))
  28.       )
  29.       (write-line (strcat "E = " (vl-princ-to-string (rtos Etotal 2 2)) " sq.m") fp)
  30.       (close fp)
  31.     )
  32.   )
  33.   (startapp "notepad" fn)
  34.   (setvar "OSMODE" 9)
  35.   (princ)
  36. )
  37.  

This code export the results in notepad and then i paste them in mtext.

I want to do two changes

1) if it possible to insert the results with mtext in autocad
2) i want  this part of the code
Code - Auto/Visual Lisp: [Select]
  1.  " " (vl-princ-to-string (rtos s 2 2 )) " x (" (vl-princ-to-string (rtos s 2 2))
  2.                   " - " (vl-princ-to-string (rtos da 2 2 )) ") x (" (vl-princ-to-string (rtos s 2 2)) " - " (vl-princ-to-string (rtos db 2 2 )) ") x ("
  3.                   (vl-princ-to-string (rtos s 2 2)) " - " (vl-princ-to-string (rtos dc 2 2 )) ")

if ti possible to be overlined

If (1) is not possible to be done then i want after paste the the results in mtext the text of the (2) be overlined.

Thanks

Title: Re: Heron formula-help with the code
Post by: PM on February 18, 2021, 03:45:19 PM
Any ideas how to  overline a Mtext?

Thanks
Title: Re: Heron formula-help with the code
Post by: BIGAL on February 18, 2021, 06:23:20 PM
I do it this way make the mtext then get the entlast using vla-put-textstring add the underline code to front of your text string.

"abcde" underlined "\\Labcde"

But text string could look like this "{\\fArial|b0|i0|c0|p34;abcde}" this seemed to work "{\\L\\fArial|b0|i0|c0|p34;abcde}"
Title: Re: Heron formula-help with the code
Post by: PM on March 18, 2021, 03:00:25 PM
Hi BIGAL. I want to overline the Mtext. Can any one fix it ?

Thanks

Title: Re: Heron formula-help with the code
Post by: BIGAL on March 18, 2021, 09:10:48 PM
Do you understand how to get the true mtext string overline was easy TextString = "{\\Oabcd}" just made some mtext set it to what I wnat and looked at tetxstring.
Title: Re: Heron formula-help with the code
Post by: ribarm on June 28, 2022, 12:24:52 AM
@Heron, or @Leibnitz?
BTW. Leibnitz also have the name...