Results 1 to 3 of 3

Thread: read table write list stuck

  1. #1
    Member
    Join Date
    2009-01
    Location
    New Jersey
    Posts
    32
    Login to Give a bone
    0

    Default read table write list stuck

    hi i have a routine that is reading from a excel csv file and writing it to a list. but it gets stuck when reading 4 cells that each contain feet and inches (ex: 10'-6") and converts them to a real using atof. it reads other strings without converting them to real numbers with no problem. in the below routine. j is already preset as 8. so in the command line it prints out "C" then it freezes then when i exit the routine "9101112" will show up. is it getting stuck in this repeat? i dont understand. i printed the (length dlst) and it returned 4 so it should exit the repeat. the parse function reads stri1 which is a line in the excel file and dcode is a comma so in the parse function it is reading the excel file until it encounters a comma and j represents how many times it does that. so that determines what cell. please help me!

    (princ "C")
    (terpri)
    (repeat (length dlst)
    (setq j (1+ j))
    (PRINC j)
    (setq nam (parse stri dcode j))
    (setq val (atof (parse stri1 dcode j)))
    (setq nvp (cons nam (list val)))
    (if (/= dstr nil)
    (setq dstr (append dstr (list nvp)))
    (setq dstr (list nvp))
    )
    ) ;end repeat
    (terpri)
    (princ "D")

  2. #2
    I could stop if I wanted to
    Join Date
    2005-09
    Location
    Canada
    Posts
    212
    Login to Give a bone
    0

    Default Re: read table write list stuck

    Quote Originally Posted by parkerfeldman View Post
    hi i have a routine that is reading from a excel csv file and writing it to a list. but it gets stuck when reading 4 cells that each contain feet and inches (ex: 10'-6") and converts them to a real using atof. it reads other strings without converting them to real numbers with no problem. in the below routine. j is already preset as 8. so in the command line it prints out "C" then it freezes then when i exit the routine "9101112" will show up. is it getting stuck in this repeat? i dont understand. i printed the (length dlst) and it returned 4 so it should exit the repeat. the parse function reads stri1 which is a line in the excel file and dcode is a comma so in the parse function it is reading the excel file until it encounters a comma and j represents how many times it does that. so that determines what cell. please help me!

    (princ "C")
    (terpri)
    (repeat (length dlst)
    (setq j (1+ j))
    (PRINC j)
    (setq nam (parse stri dcode j))
    (setq val (atof (parse stri1 dcode j)))
    (setq nvp (cons nam (list val)))
    (if (/= dstr nil)
    (setq dstr (append dstr (list nvp)))
    (setq dstr (list nvp))
    )
    ) ;end repeat
    (terpri)
    (princ "D")
    Hi,..

    I think that it will be more useful to have a bigger part of the code.
    not easy to help you with this 3 little lines..

  3. #3
    I could stop if I wanted to devitg.89838's Avatar
    Join Date
    2005-06
    Location
    CORDOBA-ARGENTINA
    Posts
    257
    Login to Give a bone
    0

    Default Re: read table write list stuck

    The fact is that the cell have a string that can not be convert to REAL in direct way , and as it also have a double quote , Lisp add a backslash before it
    see what I did .

    ;;;(setq feet (list(list "10'-6\"" "10'-6\"" "10'-6\"" "10'-6\"")))
    (setq first-row$ ( nth 0 feet))
    ;;;("10'-6\"" "10'-6\"" "10'-6\"" "10'-6\"")
    (setq first-cell$ ( nth 0 first-row$))
    ;;;"10'-6\""
    (setq first-cell# (atof first-cell$))
    ;;;10.0
    (setq first-cell$$ (distof first-cell$))
    ;;;nil


    ;;from
    ;; http://ronleigh.info/autolisp/afude12.htm
    ;;;As the cell's text have numbers (atof will take only the number until the first non digit or number char
    ;;;atof ..... (short for "alpha to floating") Returns the conversion of a string into a floating point real

    (atof "2") returns 2.0
    ;;;After
    (setq a "4.444")
    (atof a) returns 4.444

    ;;;The string cannot contain spaces or dashes, for example (atof "2 7/8") returns 2.0. If you need to handle spaces or dashes, see distof below.
    ;;;distof ..... (short for "distance to floating") Returns the conversion of a string into a floating point real

    (distof "2 7/8") ;_ returns 2.875
    (distof "2-7/8") ;_ returns 2.875
    (distof "2.34e1");_ returns 23.4

    ;;Compare atof above.


    ;;but if you strip or take off the ' the \ and the last " from the first-cell$, as to become

    (setq first-cell$ "10 6")
    ;;;"10 6"

    (setq first-cell$$ (distof first-cell$))
    ;;;nil

    It will neither work

    Maybe you will need to make a process to the string to convert the 10 Feet in " and add to the 6" .

    It will help to help you , if you can upload the CSV , and the way you want to use it.

    As I always work with metric units , I do not know if there is a way to handle it by some system variable , as LUNITS UNITS or so.

Similar Threads

  1. 2011: read/write parameters from/to af wall
    By ac_milan11 in forum Revit - API
    Replies: 0
    Last Post: 2011-09-14, 06:05 PM
  2. Read only Vs. Write Access
    By WileECoyote in forum AutoCAD General
    Replies: 16
    Last Post: 2011-06-20, 06:24 PM
  3. Mysql datasource stuck on read only
    By engineering.28250 in forum AutoCAD Map 3D - General
    Replies: 2
    Last Post: 2010-03-30, 06:07 PM
  4. help on read and write to .csv files
    By jitesh789 in forum AutoLISP
    Replies: 3
    Last Post: 2007-10-22, 11:55 AM
  5. Read and Write to DGN
    By mark.d.caldwell in forum AutoCAD General
    Replies: 4
    Last Post: 2005-04-20, 09:46 PM

Posting Permissions

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