Jesus wept, that worked perfectly! The CSV file was a bit messy but I can't complain, that's great - thanks!
I was wondering if I could pick your brain over one last thing. I'm now trying to replace the text with a foreign language, using the following works fine (not going to bother loading other definitions):
Code:
(defun c:replacer ( / relist elist olist nlist k alltext)
(command "undo" "be")
(setq relist (cdr (ReadFile "G:\\list1.csv")))
(foreach e relist
(setq elist (string->list e ","))
(setq olist (cons (nth 0 elist) olist))
(setq nlist (cons (nth 1 elist) nlist))
); foreach
(setq alltext (ssget "x" '((-4 . "<OR") (0 . "TEXT") (0 . "MTEXT") (-4 . "<AND") (0 . "INSERT") (66 . 1) (-4 . "AND>") (-4 . "OR>"))))
(if (/= alltext NIL)
(progn
(setq k 0)
(while (< k (length olist))
(txt_replace (nth k olist) (nth k nlist) T 3 "*" "*" alltext)
(setq k (1+ k))
); while
); progn
); if
(command "undo" "end")
); defun
(defun ReadFile (fname / fno txt flst e flst1)
(if (/= fname NIL)
(progn
(setq fno (open fname "r"))
(setq txt (read-line fno))
(while (/= txt nil)
(setq flst (cons txt flst))
(setq txt (read-line fno))
) ;while
(close fno)
(while (= (nth 0 flst) "")
(setq flst (cdr flst))
) ;while
(setq flst (reverse flst))
) ;progn
) ;if
(setq flst flst)
) ;defun
But instead of hard coding the CSV path, I'd like a user prompt, so did this (which doesn't work, it returns error: bad argument type: consp "LIST1.csv")
Code:
(defun c:replacer ( / relist elist olist nlist k alltext)
(command "undo" "be")
(setq relist (getfiled "Select CSV File" "" "csv" 8))
(foreach e relist
(setq elist (string->list e ","))
(setq olist (cons (nth 0 elist) olist))
(setq nlist (cons (nth 1 elist) nlist))
); foreach
(setq alltext (ssget "x" '((-4 . "<OR") (0 . "TEXT") (0 . "MTEXT") (-4 . "<AND") (0 . "INSERT") (66 . 1) (-4 . "AND>") (-4 . "OR>"))))
(if (/= alltext NIL)
(progn
(setq k 0)
(while (< k (length olist))
(txt_replace (nth k olist) (nth k nlist) T 3 "*" "*" alltext)
(setq k (1+ k))
); while
); progn
); if
(command "undo" "end")
); defun
What am i doing wrong? Cheers from a fellow Londoner