TheSwamp

Code Red => AutoLISP (Vanilla / Visual) => Topic started by: bman on August 11, 2004, 10:19:18 PM

Title: How to change precision
Post 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
 
Code: [Select]
(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)

)
Title: How to change precision
Post by: CADaver on August 12, 2004, 07:34:16 AM
Down near the bottom of the routine are a couple of ines that use RTOS

Code: [Select]
(strcat txt4 (rtos txt6 2 3) txt3)
(strcat (rtos txt6 2 3) txt3)

This piece
Code: [Select]
(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.
Title: How to change precision
Post by: daron on August 12, 2004, 08:17:32 AM
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.
Title: Learning Lisp
Post by: bman on August 12, 2004, 09:17:24 AM
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?
Title: Re: Learning Lisp
Post by: hendie on August 12, 2004, 09:32:18 AM
Quote from: bman
Where can i find some good resources on learning lisp...?


you're already at the best place !
Title: Re: Learning Lisp
Post by: Mark on August 12, 2004, 09:41:32 AM
Quote from: bman
Thanks for the tips.
Where can i find some good resources on learning lisp...are there any online course available?

http://www.smadsen.com/
Title: Re: Learning Lisp
Post by: Slim© on August 12, 2004, 10:49:11 AM
Quote from: bman
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/
Title: How to change precision
Post by: bman on August 12, 2004, 11:59:47 AM
thanks for the links