Sorry, me again. Marco Ribar, Opie & Lee Mac have helped me loads recently with a function to export all text,mtext,att-text,etc into a CSV file which worked great.
Since I have to issue loads of different drawings here in dual language, I'd like to cut out the manual task of exporting (see above) and replacing text values once I get the translations sent back (in CSV format - old column, new column).
I have written some code so far which I'm generally happy with...I just need help with writing a function to replace old vs new text! Code below, blue is the main function, red is the tricky part!:
Code:
(defun ReadFile (fname / fno txt flst e flst1); Function to read files in AutoCAD
(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
(defun String->List (strtxt delim / tmptxt k tmpchr txtlist)
(setq tmptxt "")
(setq k 1)
(while (<= k (strlen strtxt))
(setq tmpchr (substr strtxt k 1))
(cond
((/= tmpchr delim) (setq tmptxt (strcat tmptxt tmpchr)))
((= tmpchr delim) (setq txtlist (cons tmptxt txtlist)) (setq tmptxt ""))
) ;cond
(setq k (1+ k))
) ;while
(if (/= tmptxt "")
(setq txtlist (reverse (cons tmptxt txtlist)))
(setq txtlist (reverse txtlist))
) ;if
(setq txtlist txtlist)
);defun
(defun replace (/ relist elist olist nlist k alltext)
(command "undo" "be")
(setq mdatxt (cdr (ReadFile (getfiled "Read CSV" "" "csv" 4))))
(foreach e mdatxt
(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))
*****Something to replace olist with nlist?******
(setq k (1+ k))
); while
); progn
); if
(command "undo" "e")
);defun
Criteria:
Exact text matches only, I have a feeling that partial text matching could be an issue...!
Would paperspace/modelspace be an issue? If so, paperspace only is fine.
Any help would be great, and thanks in advance...
Nick