I'm looking for a lisp routine that can extract text ex. (158.9) and spit out 158'-10 13/16". Does anyone have anything like this?
|
I'm looking for a lisp routine that can extract text ex. (158.9) and spit out 158'-10 13/16". Does anyone have anything like this?
Have a look at the atof and rtos functions.
If you have a technical question, please find the appropriate forum and ask it there.
You will get a quicker response from your fellow AUGI members than if you sent it to me via a PM or email.
jUSt
Thanks! That is a great start. syntax for me would be (rtos # 4 4).... I'll start writing something now. Anymore help would be great!
this is what I have right now, and it works fine but i want to change the list to spit out (rtos i 4 4) "i" being the list.
Code:;;; (setq i (nth 1 guy_info)) (do_elev_list) (defun do_elev_list (/) (princ "\ndo_elev_list :\n") (setq elev_list nil) (foreach i guy_info (progn (setq elev_list (append elev_list (list (atof (nth 0 i))))) ) ) (princ "\nDONE do_elev_list :\n") )
Last edited by Opie; 2013-01-02 at 06:55 PM. Reason: [code] tags added ~Opie
as a sub-function
Notice the line (* i 12.0) ? from you example on the first post , i assume the numbers represents a value in feet.Code:(defun do_elev_list ( lst / elev_list) (setq elev_list nil) (foreach i lst (setq elev_list (append elev_list (list (rtos (* i 12.0) 4 4 ))) ) ) elev_list )
Example:
(setq guy_info '(158.9 542.36 8542.33))
Usage:
(do_elev_list guy_info)
Result:
("158'-10 13/16\"" "542'-4 5/16\"" "8542'-3 15/16\"")
EDIT: to use this as generic for Real value
(do_elev_list guy_info nil)Code:(defun do_elev_list ( lst m / elev_list) (setq elev_list nil) (foreach i lst (setq elev_list (append elev_list (list (rtos (* i (if m 12.0 1.0) ) 4 4 ))) ) ) elev_list )
("13'-2 7/8\"" "45'-2 3/8\"" "711'-10 5/16\"")
(do_elev_list guy_info T)
("158'-10 13/16\"" "542'-4 5/16\"" "8542'-3 15/16\"")
HTH
EDIT: busted by the code police
Last edited by pbejse; 2013-01-03 at 04:49 PM. Reason: redundancy
progn function is extra in the sub-function
One more fellas.
i need to multiply nth 1, nth 2, nth 3 and so on... by 12 to convert it to feet instead of coming out in inches. Other then that, it works great! Thanks again for the help. I'm still playing with the first routine you guys gave me to get it to work, but i have a much better understanding of what's going on.Code:(progn ;(setq 2nd_set (/ (length guy_info) 2)) (setq lc_dim1_txt (strcat (rtos (atof (nth 1 (nth 0 guy_info))))) 4 4) "±") lb_dim1_txt (strcat (rtos (atof (nth 2 (nth 0 guy_info))) 4 4) "±") la_dim1_txt (strcat (rtos (atof (nth 3 (nth 0 guy_info))) 4 4) "±") lc_e1_txt (strcat (rtos (atof (nth 9 (nth 0 guy_info))) 4 4) "±") lb_e1_txt (strcat (rtos (atof (nth 10 (nth 0 guy_info))) 4 4) "±") la_e1_txt (strcat (rtos (atof (nth 11 (nth 0 guy_info))) 4 4) "±")
The Generic code posted will multiple the values for you if the supplied argument is T (or a non nil variable)
Anyhow, included in this code is an option for prefix/suffix:
Converted to feet:Code:(defun do_elev_list ( lst m prf suf / elev_list) (setq elev_list nil) (foreach i lst (setq elev_list (append elev_list (list (strcat prf (rtos (* i (if m 12.0 1.0) ) 4 4 ) suf ))) ) ) elev_list )
(DO_ELEV_LIST guy_info T "Distance: " "±")
("Distance: 158'-10 13/16\"±" "Distance: 542'-4 5/16\"±" "Distance: 8542'-3 15/16\"±")
real value <Inches>
(DO_ELEV_LIST guy_info nil "Distance: " "±")
("Distance: 13'-2 7/8\"±" "Distance: 45'-2 3/8\"±" "Distance: 711'-10 5/16\"±")