TheSwamp
Code Red => AutoLISP (Vanilla / Visual) => Topic started by: bman on August 11, 2004, 10:19:18 PM
-
How do i change the precision to two decimal places in the following routine... it keeps giving me results to 3 decimal places. I tried changing my drawing units & it had no effect on the results
(defun c:AddText (/ txt1 txt2 cnt1 ent1)
(setq txt1 (getreal "\nEnter value to increase by (if decreasing, add a minus sign before). "))
(setq cnt1 0)
(if txt1
(progn
(setq ss (ssget '((0 . "*TEXT"))))
(while (/= cnt1 (sslength ss))
(setq ent1 (entget (ssname ss cnt1)))
(setq txt2 (cdr (assoc 1 ent1)))
(MakeSureNum txt2)
(setq cnt1 (1+ cnt1))
)
)
)
(princ)
)
;==============
(defun MakeSureNum (txt3 / cnt1 cnt2 txt4 txt5 txt6 txt7)
(setq cnt1 0
cnt2 1
)
(if (and (>= (ascii (substr txt3 1 1)) 65) (/= (ascii (substr txt3 1 1)) 32))
(while (>= (ascii (substr txt3 1 1)) 65)
(if txt4
(setq txt4 (strcat txt4 (substr txt3 1 1)))
(setq txt4 (substr txt3 1 1))
)
(setq txt3 (substr txt3 2 (strlen txt3)))
)
)
(while (= (substr txt3 1 1) " ")
(setq txt4 (strcat txt4 " "))
(setq txt3 (substr txt3 2 (strlen txt3)))
)
(if (< (ascii (substr txt3 1 1)) 65)
(while (and (<= (ascii (substr txt3 1 1)) 65) (/= (ascii (substr txt3 1 1)) 0) (/= (ascii (substr txt3 1 1)) 32))
(if txt5
(setq txt5 (strcat txt5 (substr txt3 1 1)))
(setq txt5 (substr txt3 1 1))
)
(setq txt3 (substr txt3 2 (strlen txt3)))
)
)
(setq txt5 (atof txt5))
(setq txt6 (+ txt5 txt1))
(setq txt7
(if txt4
(strcat txt4 (rtos txt6 2 3) txt3)
(strcat (rtos txt6 2 3) txt3)
)
)
(setq ent1 (subst (cons 1 txt7) (assoc 1 ent1) ent1))
(entmod ent1)
)
-
Down near the bottom of the routine are a couple of ines that use RTOS
(strcat txt4 (rtos txt6 2 3) txt3)
(strcat (rtos txt6 2 3) txt3)
This piece
(rtos txt6 2 3)
RTOS is "RealToString", so it's taking the variable txt6 and making it a string. The following 2, means it is to use decimal units (4 would be ft-in) and the last 3 means 3 decimal places. If the 3 is left out, it will use the decimal place setting from the drawing LUPREC.
-
And you claim to not be able to write this stuff Cadaver. You seem to have a good understanding of it.
Changing the 3 to a 2 in Cadaver's explanation would give you the results you're looking for. That last number is the precision parameter or rtos.
-
Thanks for the tips.
Where can i find some good resources on learning lisp...are there any online course available? Do most of the local community colleges offer beginner courses?
-
Where can i find some good resources on learning lisp...?
you're already at the best place !
-
Thanks for the tips.
Where can i find some good resources on learning lisp...are there any online course available?
http://www.smadsen.com/
-
Thanks for the tips.
Where can i find some good resources on learning lisp...are there any online course available? Do most of the local community colleges offer beginner courses?
Here is another good site:
http://www.afralisp.com/
-
thanks for the links