- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hi,
I have many DWG files and I have some text to replace in these DWG files.
And I have a CSV file containing the name of these files and the values will be assigned to each file as follows:
The text to be replaced in DWG files is fixed. So this part is easy.
COLUMN 3 --> QDT
COLUMN 4 --> QSC
COLUMN 5 --> QFM
COLUMN 9 --> QAE
COLUMN 10 -> QSAE
COLUMN 11 -> QSY
COLUMN 12 -> QSSY
COLUMN 13 -> QLN
COLUMN 14 -> QDCT
COLUMN 15 -> QDCN
The thing that I want to do is:
1 - Get the values from the CSV table by looking at the name from the first column.
2 - Replace the values in the DWG file with the values from the table.
3 - Do these for all the files in the directory.
Well actually I created a AutoLisp Program that does all of this except the last part. I can't run it for multiple files.
1 - I used LM:ReadCSV to read the table.
(setq csv_file "C:/VARIABLES.csv")
(setq csv_data (LM:readcsv csv_file)) ;WHOLE TABLE
2 - I used this code to Find&Replace method:
(defun change_it (old new)
(setq OldTxt old
NewTxt new)
(setq ss (ssget "x" '((0 . "TEXT,MTEXT"))))
(setq i (sslength ss))
(while (not (minusp (setq i (1- i))))
(setq oText (vlax-ename->vla-object (ssname ss i)))
(setq Txt (vlax-get-property oText 'TextString))
(if (vl-string-search OldTxt txt)
(progn
(setq newChg (vl-string-subst NewTxt OldTxt txt))
(vlax-put-property oText 'TextString newchg)
(vlax-invoke-method oText 'Update)
)
)
)
(princ)
)
3 - I used this function to make all the changes for a single file:
(defun _replace_all_text ()
(foreach line csv_data
(setq pafta_no (nth 0 line)) ;Gets the first column to get the file name
(if (= (car line) file_name) ;Gets the line where the filename matches.
(progn
(change_it "QDT" (nth 2 line)) ;DATE QDT
(change_it "QSC" (nth 3 line)) ;SCALE QSC
(change_it "QFM" (nth 4 line)) ;FORMAT QFM
(change_it "QAE" (nth 8 line)) ;AREA QAE
(change_it "QSAE" (nth 9 line)) ;SUBAREA QSAE
(change_it "QSY" (nth 10 line)) ;SYSTEM QSY
(change_it "QSSY" (nth 11 line));SUBSYSTEM QSSY
(change_it "QLN" (nth 12 line)) ;LANGUAGE QLN
(change_it "QDCT" (nth 13 line));DOCTYPE QDCT
(change_it "QDCN" (nth 14 line));DOCNO QDCN
)
)
)
)
I tried to use BFIND program from "lee-mac" but I couldn't manage to use it with an external CSV file.
I also tried to use objectdbx wrapper from "lee-mac" but it doesn't work since "change_it" function has some commands such as "ssget".
I don't want to use an external software due to privacy reasons. What is your suggestions?
Solved! Go to Solution.