marshrunner757 Posted May 10, 2017 Posted May 10, 2017 I am looking for a lisp to print a batch of drawings from folder to pdf. Only print model space. I've searched and found a couple but didn't work. I'm running autocad 2017. Thanks for any help. Sent from my SAMSUNG-SM-G930A using Tapatalk Quote
CafeJr Posted May 10, 2017 Posted May 10, 2017 I am looking for a lisp to print a batch of drawings from folder to pdf. Only print model space. I've searched and found a couple but didn't work. I'm running autocad 2017. Thanks for any help. Sent from my SAMSUNG-SM-G930A using Tapatalk Hi marshrunner757... Do you wanna print many files of a folder, all of this in paper-space? How many paper-space for drawing or only one? The bachplot its a common tool and easy to use from the main autocad menu, did you tried it? Sorry if I did any stupid question... He he he... Quote
marshrunner757 Posted May 10, 2017 Author Posted May 10, 2017 I have tried the publish built into autocad. Typically, I'll have 100+ drawings to print. I want to print only the model space and want it to use my acad.ctb. I currently open each drawing and run a simple lisp that sets the parameters and prints the current drawing. Open the next drawing, run the lisp and so on. I want to be able to open autocad, run the lisp and it print all drawings in a folder. Thanks Sent from my SAMSUNG-SM-G930A using Tapatalk Quote
BIGAL Posted May 11, 2017 Posted May 11, 2017 Thats easy do what your doing now but in a script, the only problem I see is when you run your lisp now does it ask for user input like pick a window ? If so you can not automate that part. Even so. open dwg1 (load "myplot") close N open dwg2 (load "myplot") close N open dwg3 (load "myplot") close N Quote
maratovich Posted May 11, 2017 Posted May 11, 2017 marshrunner757 Do you want to specify a folder? Do not write its name every time? Do you have many drawings in one model? Want multi-sheet PDF? Quote
CafeJr Posted May 11, 2017 Posted May 11, 2017 I have tried the publish built into autocad. Typically, I'll have 100+ drawings to print. I want to print only the model space and want it to use my acad.ctb. I currently open each drawing and run a simple lisp that sets the parameters and prints the current drawing. Open the next drawing, run the lisp and so on. I want to be able to open autocad, run the lisp and it print all drawings in a folder. Thanks Do you have any lisp code that you use?... As you are talking, it's so easy you use the Publish Cad tool, maybe the number of drawing could cause a delay, but I think that's possible without any problem. Quote
marshrunner757 Posted May 11, 2017 Author Posted May 11, 2017 First, I haven't written lisp in about 8 years so I am very rusty and not sure about using scripts. Second, I only want to print the model, we don't use layouts at our facility. And yes, I'd like to specify the folder or at least use a certain folder each time. Third, the publish tool does work but, I want them all to print B&W. When I try it, some are B&W and some are color. Sent from my SAMSUNG-SM-G930A using Tapatalk Quote
CafeJr Posted May 11, 2017 Posted May 11, 2017 First, I haven't written lisp in about 8 years so I am very rusty and not sure about using scripts. Second, I only want to print the model, we don't use layouts at our facility. And yes, I'd like to specify the folder or at least use a certain folder each time. Third, the publish tool does work but, I want them all to print B&W. When I try it, some are B&W and some are color. Ok!... So, we have two basic ways, your publish printing with color it's because you need to create a .ctb file with your configurations this is easy to do. Another way is using the part code below, so to many files I'll look how do it (maybe I'll need a help of our Master Lisps here). (command "-plot" "yes" "model" "Foxit Reader PDF Printer"; Printer name "A4" "m" "landscape" "no" "Window" (trans (vlax-safearray->list mn) 0 1) (trans (vlax-safearray->list mx) 0 1) "fit" "0.00,0.25" "yes" "monochrome.ctb"; Default CTB file (with your modifications) "yes" "no" "no" "yes" "yes" ) Quote
marshrunner757 Posted May 11, 2017 Author Posted May 11, 2017 I have a ctb file. How do you specify a ctb using publish? Our drawings are worked on by several contract companies. So when they come back, there's all different parameters in the drawings. Sent from my SAMSUNG-SM-G930A using Tapatalk Quote
marshrunner757 Posted May 11, 2017 Author Posted May 11, 2017 I think I've attached a drawing. Also see below for code I'm working on. It will only open the first drawing in the folder. (defun C:DWG2PDF (/ ACADOBJ DOC DWG_DIR DWG_LST NAME SDI) (command "attreq" "0") (command "-layer" "s" "0" "c" "1" "" "") (defun CJW-FILE-GET (MSG / WINSHELL SHFOLDER PATH CATCHIT) (setq WINSHELL (vlax-create-object "Shell.Application")) (setq SHFOLDER (vlax-invoke-method WINSHELL 'BROWSEFORFOLDER 0 MSG 1) ) (setq CATCHIT (vl-catch-all-apply '(lambda () (setq SHFOLDER (vlax-get-property SHFOLDER 'SELF)) (setq PATH (vlax-get-property SHFOLDER 'PATH)) ) ) ) (if (vl-catch-all-error-p CATCHIT) NIL PATH ) ) (setvar "CMDECHO" 0) ;;; (alert "\nNote: backup original!") (if (and (setq DWG_DIR (CJW-FILE-GET "to select the DWG file folder?")) (setq DWG_LST (vl-directory-files DWG_DIR "*.DWG" 1)) ) (progn (foreach DWG DWG_LST (if (setq SS (ssget "x")) (command "._ERASE" SS "") ) (setq DWG (strcat DWG_DIR "\\" DWG)) (setq FILENAME (strcat DWG_DIR "\\" (vl-filename-base DWG) ".DWG")) (command ".-INSERT" DWG "_NON" '(0. 0. 0.) "1" "1" "0") (command "._ZOOM" "_E") (command "._zoom" ".9xp") (COMMAND "OPEN" FILENAME) (command "-PLOT" "yes" "model" "Adobe PDF.pc3" "11 x 17" "I" "landscape" "no" "extents" "fit" "center" "yes" "acad.ctb" "yes" "w" "no" "no" "Y") (COMMAND "CLOSE" "N") ) (alert "DWG2PDF Finished!!!") ) ) (princ) ) The above code was modified from a Lisp I have for generating slides which works perfectly. See below for that. (defun C:DWG2SLD (/ ACADOBJ DOC DWG_DIR DWG_LST NAME SDI) (command "attreq" "0") (command "-layer" "s" "0" "c" "1" "" "") (defun CJW-FILE-GET (MSG / WINSHELL SHFOLDER PATH CATCHIT) (setq WINSHELL (vlax-create-object "Shell.Application")) (setq SHFOLDER (vlax-invoke-method WINSHELL 'BROWSEFORFOLDER 0 MSG 1) ) (setq CATCHIT (vl-catch-all-apply '(lambda () (setq SHFOLDER (vlax-get-property SHFOLDER 'SELF)) (setq PATH (vlax-get-property SHFOLDER 'PATH)) ) ) ) (if (vl-catch-all-error-p CATCHIT) NIL PATH ) ) (setvar "CMDECHO" 0) ;;; (alert "\nNote: backup original!") (if (and (setq DWG_DIR (CJW-FILE-GET "to select the DWG file folder?")) (setq DWG_LST (vl-directory-files DWG_DIR "*.DWG" 1)) ) (progn (foreach DWG DWG_LST (if (setq SS (ssget "x")) (command "._ERASE" SS "") ) (setq DWG (strcat DWG_DIR "\\" DWG)) (setq SLD (strcat DWG_DIR "\\" (vl-filename-base DWG) ".sld")) (command ".-INSERT" DWG "_NON" '(0. 0. 0.) "1" "1" "0") (command "._ZOOM" "_E") (command "._zoom" ".9xp") (command "._MSLIDE" SLD) (print SLD) ) (command "attreq" "1") (alert "DWG2SLD Finished!!!") ) ) (princ) ) test.dwg Quote
CafeJr Posted May 11, 2017 Posted May 11, 2017 I think I've attached a drawing. Also see below for code I'm working on. It will only open the first drawing in the folder. (defun C:DWG2PDF (/ ACADOBJ DOC DWG_DIR DWG_LST NAME SDI) ... Try to use the # here to insert one code... will split the coments of the code. I still loking for one code that could help you!... Quote
marshrunner757 Posted May 11, 2017 Author Posted May 11, 2017 Not sure I follow you on the #. Sorry Sent from my SAMSUNG-SM-G930A using Tapatalk Quote
CafeJr Posted May 11, 2017 Posted May 11, 2017 Below one code that maybe can help: (vl-load-com) ;; http://www.lee-mac.com/listbox.html ;; List Box - Lee Mac ;; Displays a DCL list box allowing the user to make a selection from the supplied data. ;; msg - [str] Dialog label ;; lst - [lst] List of strings to display ;; bit - [int] 1=allow multiple; 2=return indexes ;; Returns: [lst] List of selected items/indexes, else nil (defun LM:listbox (msg lst bit / dch des tmp rtn) (cond ((not (and (setq tmp (vl-filename-mktemp nil nil ".dcl")) (setq des (open tmp "w")) (write-line (strcat "listbox:dialog{label=\"" msg "\";spacer;:list_box{key=\"list\";multiple_select=" (if (= 1 (logand 1 bit)) "true" "false" ) ";width=50;height=15;}spacer;ok_cancel;}" ) des ) (not (close des)) (< 0 (setq dch (load_dialog tmp))) (new_dialog "listbox" dch) ) ) (prompt "\nError Loading List Box Dialog.") ) (t (start_list "list") (foreach itm lst (add_list itm)) (end_list) (setq rtn (set_tile "list" "0")) (action_tile "list" "(setq rtn $value)") (setq rtn (if (= 1 (start_dialog)) (if (= 2 (logand 2 bit)) (read (strcat "(" rtn ")")) (mapcar '(lambda (x) (nth x lst)) (read (strcat "(" rtn ")"))) ) ) ) ) ) (if (< 0 dch) (unload_dialog dch) ) (if (and tmp (setq tmp (findfile tmp))) (vl-file-delete tmp) ) rtn ) (defun c:my_plot (/ *error* dirlst dirpath dwgname files ofile plotdir scrfile) (defun *error* (msg) (if ofile (close ofile) ) (cond ((not msg)) ((member msg '("Function cancelled" "quit / exit abort"))) ((princ (strcat "\n** Error: " msg " ** "))) ) (princ) ) (if (and (setq dirpath (acet-ui-pickdir "Select Folder to Process... ")) (setq plotdir (strcat DirPath "\\PDF files")) (setq dirlst (vl-directory-files dirPath "*.dwg" 1)) (setq files (LM:listbox "Select Files to plot to PDF... " dirlst 1)) ) (progn (if (not (findfile plotdir)) (vl-mkdir plotdir) ) (if (= (getvar 'SDI) 1) (setvar 'SDI 0) ) (setvar 'BACKGROUNDPLOT 2) (setq scrfile (strcat (getenv "Temp") "\\My_plot.scr") ofile (open scrfile "w") ) (foreach file files (setq dwgname (strcat "\"" dirpath "\\" file "\"")) (write-line "_.open" ofile) (write-line dwgName ofile) (write-line "(load \"My_Plot_V03.lsp\")" ofile) (write-line "_.model" ofile) (write-line "(my_plot)" ofile) ) (close ofile) (command "_.script" scrfile) ) ) (princ) ) (defun my_plot (/ file i mn mx pt1 pt2 ss ss1) (if (setq ss (ssget "_X" (list '(0 . "LWPOLYLINE") '(8 . "OUTLINE") (cons 410 (getvar 'CTAB)) '(-4 . "&=") '(70 . 1)) ) ) (repeat (setq i (sslength ss)) (vla-getboundingbox (vlax-ename->vla-object (ssname ss (setq i (1- i)))) 'mn 'mx) (setq pt1 (vlax-safearray->list mn) pt2 (vlax-safearray->list mx) ) (command "_.zoom" pt1 pt2) (if (setq ss1 (ssget "_C" pt1 pt2 '((0 . "TEXT") (8 . "TitleText")))) (progn (setq file (strcat (getvar 'DWGPREFIX) "PDF files\\" (cdr (assoc 1 (entget (ssname ss1 0)))) " - Alignment Sheet" ) ) (if (findfile file) (vl-file-delete file) ) (command "-plot" "yes" "Model" "DWG To PDF.pc3" "ISO A1 (594.00 x 841.00 MM)" "_m" "_l" "_n" "_w" pt1 pt2 "_F" "_C" "_Y" "acad.ctb" "_Y" "_N" file "_Y" "_Y") ) ) ) ) (if (/= (getvar 'DBMOD) 0) (command "_.close" "_Y") (command "_.close") ) (princ) ) *** Thanks Lee-Mac for the code!... Quote
CafeJr Posted May 11, 2017 Posted May 11, 2017 You can also write: (CODE)...here the code...(/CODE) - change the () to []. The code above I tryed but not work so good, I don't why yet!?... Quote
maratovich Posted May 11, 2017 Posted May 11, 2017 Here there is a choice of all files in folder. This is batch printing from model Quote
CafeJr Posted May 11, 2017 Posted May 11, 2017 Here there is a choice of all files in folder.This is batch printing from model Thanks!... Very nice!... Quote
CafeJr Posted May 11, 2017 Posted May 11, 2017 The code above I tryed but not work so good, I don't why yet!?... I've found why it wasn't work, need to put the lisp file at dwg folder with the drawings. Quote
marshrunner757 Posted May 11, 2017 Author Posted May 11, 2017 Not working for me. It's opening the drawings but not printing Sent from my SAMSUNG-SM-G930A using Tapatalk Quote
marshrunner757 Posted May 11, 2017 Author Posted May 11, 2017 #ERROR BELOW# Cannot invoke (command) from *error* without prior call to (*push-error-using-command*). Converting (command) calls to (command-s) is recommended. Command: _.model Command: (my_plot) Cannot invoke (command) from *error* without prior call to (*push-error-using-command*). Converting (command) calls to (command-s) is recommended. However, if I cut the following line from the lisp and paste it in the command line, it will print the current drawing to PDF. #CODE (command "-plot" "yes" "Model" "Adobe PDF.pc3" "11 x 17" "I" "_l" "_n" "extents" "_F" "_C" "_Y" "acad.ctb" "_Y" "_N" file "_Y" "_Y") Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.