Results 1 to 9 of 9

Thread: Need help to convert a string to feet-in-fraction

  1. #1
    Member
    Join Date
    2013-01
    Posts
    4
    Login to Give a bone
    0

    Default Need help to convert a string to feet-in-fraction

    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?

  2. #2
    Administrator Opie's Avatar
    Join Date
    2002-01
    Location
    jUSt Here (a lot)
    Posts
    9,106
    Login to Give a bone
    0

    Default Re: Need help to convert a string to feet-in-fraction

    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

  3. #3
    Member
    Join Date
    2013-01
    Posts
    4
    Login to Give a bone
    0

    Default Re: Need help to convert a string to feet-in-fraction

    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!

  4. #4
    Member
    Join Date
    2013-01
    Posts
    4
    Login to Give a bone
    0

    Default Re: Need help to convert a string to feet-in-fraction

    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

  5. #5
    All AUGI, all the time
    Join Date
    2010-10
    Posts
    535
    Login to Give a bone
    0

    Default Re: Need help to convert a string to feet-in-fraction

    as a sub-function

    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
    )
    Notice the line (* i 12.0) ? from you example on the first post , i assume the numbers represents a value in feet.

    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

    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
    )
    (do_elev_list guy_info nil)
    ("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

  6. #6
    All AUGI, all the time
    Join Date
    2010-06
    Posts
    962
    Login to Give a bone
    0

    Default Re: Need help to convert a string to feet-in-fraction

    progn function is extra in the sub-function

  7. #7
    All AUGI, all the time
    Join Date
    2010-10
    Posts
    535
    Login to Give a bone
    0

    Default Re: Need help to convert a string to feet-in-fraction

    Quote Originally Posted by Tharwat View Post
    progn function is extra in the sub-function
    Bummer, serves me right not checking the OP's code thoroughly

    Thanks tharwat

  8. #8
    Member
    Join Date
    2013-01
    Posts
    4
    Login to Give a bone
    0

    Default Re: Need help to convert a string to feet-in-fraction

    One more fellas.
    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) "±")
    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.

  9. #9
    All AUGI, all the time
    Join Date
    2010-10
    Posts
    535
    Login to Give a bone
    0

    Default Re: Need help to convert a string to feet-in-fraction

    Quote Originally Posted by Jewbacca View Post
    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. ....
    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:
    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
    )
    Converted to feet:
    (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\"±")

Similar Threads

  1. Convert Field Value to String?
    By stusic in forum AutoLISP
    Replies: 1
    Last Post: 2012-04-04, 04:03 PM
  2. Convert string to variable
    By davila.vanegas in forum AutoLISP
    Replies: 8
    Last Post: 2010-07-06, 12:42 PM
  3. Need to convert a string into a list.
    By Mike_R in forum AutoLISP
    Replies: 2
    Last Post: 2008-02-04, 06:56 PM
  4. Using Map convert to feet
    By dstapp.144268 in forum AutoCAD Map 3D - General
    Replies: 2
    Last Post: 2007-08-08, 10:28 PM
  5. convert a list to a string
    By ccowgill in forum AutoLISP
    Replies: 3
    Last Post: 2006-09-21, 10:18 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •