Jump to content

Leaderboard

Popular Content

Showing content with the highest reputation on 10/31/2020 in all areas

  1. Here is some useful subfunction from Lee Mac, (LM:data->xdata) that may be of help.
    1 point
  2. Keep in mind that this forum and www.theswamp.org should not be abused as a free software service. To always ask for code and never make any attempt to learn to code yourself, is not a good idea in the long run. Let's just say I am in a very, very good mood: ; Library function (defun KGA_Data_FileRead (fnm / lst ptr str) (if (setq ptr (open fnm "r")) (progn (while (setq str (read-line ptr)) (setq lst (cons str lst)) ) (close ptr) (reverse lst) ) ) ) ; Library function (defun KGA_Data_FileWrite (fnm lst / ptr) (if (setq ptr (open fnm "w")) (progn (foreach str lst (write-line str ptr) ) (close ptr) T ) ) ) ; Library function (defun KGA_String_Join (strLst delim) (if strLst (apply 'strcat (cons (car strLst) (mapcar '(lambda (a) (strcat delim a)) (cdr strLst)) ) ) "" ) ) ; Library function (defun KGA_String_PadLeft (str ch len) (repeat (- len (strlen str)) (setq str (strcat ch str)) ) str ) ; Library function (defun KGA_String_Tokenize (str delim / ret sub) (setq delim (append (vl-string->list delim) '(nil))) (setq str (vl-string->list str)) (repeat (1+ (length str)) (if (vl-position (car str) delim) (progn (setq ret (cons (vl-list->string (reverse sub)) ret)) (setq sub nil) ) (setq sub (cons (car str) sub)) ) (setq str (cdr str)) ) (reverse ret) ) ; 20190417 ; (CSV_To_GSI_Read "C:\\Downloads\\test.csv") (defun CSV_To_GSI_Read (fnm) (mapcar '(lambda (str / lst) (setq lst (KGA_String_Tokenize str ",")) (cons (car lst) (mapcar 'read (cdr lst))) ) (KGA_Data_FileRead fnm) ) ) ; 20190417 ; (CSV_To_GSI_Sort (CSV_To_GSI_Read "C:\\Downloads\\test.csv")) (defun CSV_To_GSI_Sort (lst) ; Lst is output from CSV_To_GSI_Read. (vl-sort lst '(lambda (a b) (< (car a) (car b))) ) ) ; 20190417 ; *110122+00000000000000S9 ; idx label ; (CSV_To_GSI_FormatPointId 122 "S9") (defun CSV_To_GSI_FormatPointId (idx lab) (strcat "*11" (KGA_String_PadLeft (itoa idx) "0" 4) "+" (KGA_String_PadLeft lab "0" 16) ) ) ; 20190417 ; 81..10+0000000304279082 ; (CSV_To_GSI_FormatCoord "81" 304279.082) (defun CSV_To_GSI_FormatCoord (axisPre coord) ; AxisPre is "81", "82" or "83". (strcat axisPre "..10+" (KGA_String_PadLeft (rtos (* 1000 coord) 2 0) "0" 16) ) ) ; 20190417 ; (CSV_To_GSI_Convert (CSV_To_GSI_Sort (CSV_To_GSI_Read "C:\\Downloads\\test.csv"))) (defun CSV_To_GSI_Convert (lst / i) ; Lst is (sorted) output from CSV_To_GSI_Read. (setq i 0) (mapcar '(lambda (sub) (strcat (CSV_To_GSI_FormatPointId (setq i (1+ i)) (car sub)) " " (CSV_To_GSI_FormatCoord "81" (cadr sub)) " " (CSV_To_GSI_FormatCoord "82" (caddr sub)) " " (CSV_To_GSI_FormatCoord "83" (cadddr sub)) " " ) ) lst ) ) ; 20190417 (defun C:CSV_To_GSI ( / lst src trg) (if (and (setq src (getfiled "CSV file" (getvar 'dwgprefix) "csv" 0)) (setq lst (CSV_To_GSI_Read src)) (setq trg (getfiled "GSI file" (strcat (vl-filename-directory src) "\\") "gsi" 1)) ) (KGA_Data_FileWrite trg (CSV_To_GSI_Convert (CSV_To_GSI_Sort lst)) ) ) (princ) )
    1 point
×
×
  • Create New...