- ;;-----------------------=={ Read CSV }==---------------------;; ;; ;; ;; Parses a CSV file into a matrix list of cell values. ;; ;;------------------------------------------------------------;; ;; Author: Lee Mac, Copyright © 2012 - www.lee-mac.com ;; ;;------------------------------------------------------------;; ;; Arguments: ;; ;; filename - filename of CSV file to read ;; ;;------------------------------------------------------------;; ;; Returns: List of lists - sublist is row of cell values ;; ;;------------------------------------------------------------;;
- ;;-------------------------------------------------------------------------------;;
- (defun LM:ReadCSV ( filename / _replacequotes _csv->lst file line lst )
-
- (defun _replacequotes ( str / pos )
- (setq pos 0)
- (while (setq pos (vl-string-search """" str pos))
- (setq str (vl-string-subst """ """" str pos)
- pos (1+ pos)
- )
- )
- str
- )
- (defun _csv->lst ( str pos / s )
- (cond
- ( (null (setq pos (vl-string-position 44 str pos)))
- (if (wcmatch str ""*"")
- (list (_replacequotes (substr str 2 (- (strlen str) 2))))
- (list str)
- )
- )
- ( (wcmatch (setq s (substr str 1 pos)) ""*"")
- (cons
- (_replacequotes (substr str 2 (- pos 2)))
- (_csv->lst (substr str (+ pos 2)) 0)
- )
- )
- ( (wcmatch s ""*[~"]")
- (_csv->lst str (+ pos 2))
- )
- ( (cons s (_csv->lst (substr str (+ pos 2)) 0)))
- )
- )
- (if (setq file (open filename "r"))
- (progn
- (while (setq line (read-line file))
- (setq lst (cons (_csv->lst line 0) lst))
- )
- (close file)
- )
- )
- (reverse lst)
- )
- ;;-------------------------------------------------------------------------------;;
- (defun c:updatedwgs ( fromfilename tofilename fromlayername tolayername / data file )
- (if
- (and
- (setq file (getfiled "Select CSV File" "" "csv" 16))
- (setq data (LM:ReadCSV file))
- )
- (progn
- (princ "\n(")
- (foreach line data
- (progn
- (princ "\n ") (prin1 line)
- (setq fromfilename (car line)
- tofilename (cadr line)
- fromlayername (caddr line)
- tolayername (cadddr line)
- )
- )
-
- (if (tblsearch "LAYER" fromlayername) ; found the layer
- (progn
- (command "-layer" "U" fromlayername "")
- (command "rename" "layer" fromlayername tolayername)
- )
- )
- )
- )
- (princ "\n)")
- )
-
- (princ)
- )
- ;;-------------------------------------------------------------------------------;;