Results 1 to 4 of 4

Thread: help on read and write to .csv files

  1. #1
    Member
    Join Date
    2007-10
    Posts
    41
    Login to Give a bone
    0

    Smile help on read and write to .csv files

    Hi
    Can any one please help me on read and write commands in lisp how to use it and how does read command read from a file for eg i want to plot a traverse in cad my csv will have
    point, easting,northing,rl,code. how to read this and how to decide on decimal places
    Also if i have a polygon how can i select the line and get all the coordinates of the end point

  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: help on read and write to .csv files

    You, of course, need to open the file for reading and assign this file pointer to a variable. You can then read-line one line from the file pointer at a time. You could then loop through this string while looking for the commas, which delimit your fields (point, easting, northing, etc.).

    Of course, if you wanted to write-line this information to an opened file for write.
    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
    2007-10
    Posts
    41
    Login to Give a bone
    0

    Default Re: help on read and write to .csv files

    Thanks but i need to know that when i read a file what does it takes first suppose i have 5 columns in csv format i.e 5 values separated by commas and i have 10 rows do i have to define column width or use car functions if so please tell me how to.

  4. #4
    Active Member
    Join Date
    2015-12
    Location
    Utah
    Posts
    69
    Login to Give a bone
    0

    Default Re: help on read and write to .csv files

    This is quick and dirty, no testing, no error checking:

    Code:
    (defun ReadCSVFile(FileName / rtlist)
      (setq fileh (open FileName "r"))
      (while (setq line (read-line fileh))
        (setq rtlist (cons (str2list line ",") rtlist))
        )
      (reverse rtlist)
      )
    
    ;;;By John Uhden, as posted to the autodesk customization newsgroup 06 Feb 2003
    (defun Str2List (str pat / i j n lst)
      (cond
        ((/= (type str)(type pat) 'STR))
        ((= str pat)'(""))
        (T
         (setq i 0 n (strlen pat))
         (while (setq j (vl-string-search pat str i))
           (setq lst (cons (substr str (1+ i)(- j i)) lst)
    	     i (+ j n)
    	     )
           )
         (reverse (cons (substr str (1+ i)) lst))
         )
        )
      )
    Note: This fails on values with a quoted comma

    Here is a thread on TheSwamp.org with code to deal with quoted commas: http://www.theswamp.org/index.php?topic=19527.0
    Last edited by mweaver; 2007-10-23 at 03:19 AM. Reason: Added note; [code] tags added by Opie

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. Attempted to read or write protected memory?
    By c-hawk in forum Revit - API
    Replies: 2
    Last Post: 2009-08-12, 02:32 PM
  4. Read / Write To Text File
    By caddog71 in forum VBA/COM Interop
    Replies: 2
    Last Post: 2008-05-27, 06:40 PM
  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
  •