Hi all, my lisp knowledge is very limited so I was hoping someone could help mw with this. I have a lisp which I copied from a Autodesk forum (https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/export-to-pdf-lisp-routine/td-p/5704... and tweaked a little to suit my needs. It basically plot all layout tabs to PDF (with revision letter at the end of the pdf name). It works just fine.
Now, what I want it to do is to instead of printing all layouts, read a csv file "title_block.csv" and only plot to PDF layouts named in that csv file.
I used Lee Mac's code/functions to read a csv file in the same folder as the .dwg (title_block.csv) which has only one set of data in column 1. (layout to be ploted, eg: row1 "Layout" row2 "200" row3 "300"). However it doesn't send the command "_.-PLOT" and I get erros like: Unknown command "PC3". Press F1 for help. Unknown command "00 X 297.00 MM)". Press F1 for help.... etc
Would someone be able to tell me what is wrong with it?
#(defun c:PDF ( / data file ) (command "MODEL") (setq cmd (getvar 'cmdecho)) (setvar 'cmdecho 0) ; check that pdf directory exists (setq dwgpre (strcat (getvar "dwgprefix") "PDF")) ;if doesn't exist create one (if (= (vl-file-directory-p dwgpre) nil) (vl-mkdir dwgpre) ) (setq pdfname (strcat (vl-filename-base (getvar "dwgname")))) (if (and (setq file (findfile "title_block.csv")) (setq data (cdr(LM:readcsv file))) ) (progn ;(princ "\n(") (foreach layout data ;(princ "\n ") (prin1 layout) ;(princ "\n)") (command "_.-PLOT" "Y" ;Detailed plot configuration? [yes/no] Layout ;Enter Layout name or [?],layout1: "Dwg To PDF.pc3" ;Enter an output device name "ISO full bleed A3 (420.00 x 297.00 MM)" ;Enter paper size "M" ;Paper units: "M" for mm "L" ;Enter drawing orientation: "L" for Landscaping "N" ;Upside down? "N" "E" ;"E" for extents "1:2" ;Plot scale: Custom "1:2" "C" ;Counter "c" "Y" ;Plot Style? "y" "A3.ctb" ;Enter plot style: "A3.ctb" "Y" ;Plot line weights? "N" ;plot line scaling? "N" ;Paper space first? "N" ;Hide? (strcat dwgpre "\\" pdfname "-" (getvar "ctab") ".pdf") ;Directory to save "N" ;save changes to page setup? "Y" ;proceed with plot? );command (prompt "\nSuccessfully Plot.....") ;(princ "\n)") ) );progn ) (princ) ) (princ) ;; Read CSV - Lee Mac ;; Parses a CSV file into a matrix list of cell values. ;; csv - [str] filename of CSV file to read (defun LM:readcsv ( csv / des lst sep str ) (if (setq des (open csv "r")) (progn (setq sep (cond ((vl-registry-read "HKEY_CURRENT_USER\\Control Panel\\International" "sList")) (","))) (while (setq str (read-line des)) (setq lst (cons (LM:csv->lst str sep 0) lst)) ) (close des) ) ) (reverse lst) ) ;; CSV -> List - Lee Mac ;; Parses a line from a CSV file into a list of cell values. ;; str - [str] string read from CSV file ;; sep - [str] CSV separator token ;; pos - [int] initial position index (always zero) (defun LM:csv->lst ( str sep pos / s ) (cond ( (not (setq pos (vl-string-search sep str pos))) (if (wcmatch str "\"*\"") (list (LM:csv-replacequotes (substr str 2 (- (strlen str) 2)))) (list str) ) ) ( (or (wcmatch (setq s (substr str 1 pos)) "\"*[~\"]") (and (wcmatch s "~*[~\"]*") (= 1 (logand 1 pos))) ) (LM:csv->lst str sep (+ pos 2)) ) ( (wcmatch s "\"*\"") (cons (LM:csv-replacequotes (substr str 2 (- pos 2))) (LM:csv->lst (substr str (+ pos 2)) sep 0) ) ) ( (cons s (LM:csv->lst (substr str (+ pos 2)) sep 0))) ) ) (defun LM:csv-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 ) #
Solved! Go to Solution.
Solved by kleber3NH6F. Go to Solution.
Maybe try to replace:
(strcat dwgpre "\\" pdfname "-" (getvar "ctab") ".pdf")
with
(strcat dwgpre "\\" pdfname "-" Layout ".pdf")
If it fails, turn the echo on and copy-past all the command-line listing.
Hi BeeKeeCZ,
Thanks for replying. I have actually found the answer from another forum. I need to change the line:
(foreach layout (list data)
to:
(foreach layout (mapcar 'car data)
That did the trick!
Thanks anyway
Can't find what you're looking for? Ask the community or share your knowledge.